home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / phigs / ptk.lha / ptk / source / library / dbug.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-01  |  92.6 KB  |  3,032 lines

  1. /*----------------------------------------------------------------------------
  2.  
  3.   Module name: PHIGS Debugger.
  4.  
  5.   Author: Steve Larkin.
  6.  
  7.   Function: This module contains the PHIGS Debugger.
  8.  
  9.   Dependencies:
  10.  
  11.   Internal function list: 
  12.  
  13.   External function list: 
  14.  
  15.   Modification history: (Version), (Date), (name), (Description).
  16.  
  17.   1.0, 23rd August 1988, S. Larkin, First version.
  18.  
  19.   2.0, 30th October 1991, G. Williams, Translated to C.
  20.  
  21. ----------------------------------------------------------------------------*/
  22.  
  23. #include <stdio.h>
  24. #include <math.h>
  25. #include <phigs.h>
  26. #include "ptk.h"
  27.  
  28. #ifdef SUN
  29. #define PICKDEV 2
  30. #define LOCDEV 1
  31. #endif
  32. #ifdef HP
  33. #define PICKDEV 2
  34. #define LOCDEV 1
  35. #endif
  36. #ifdef PEXSI
  37. #define LOCDEV 1
  38. #define PICKDEV 1
  39. #endif
  40.  
  41. /* set a maximum limit on the number of elements to
  42. ** put in the structure content window. This is to enable
  43. ** the debugger to work with large structures ~3000 elements.
  44. ** Rebuilding the content diagram during scrolling etc. should be
  45. ** invisible to the user.
  46. */
  47. #define PTKSTCTLIMIT 100
  48.  
  49. /*--------------------------------------------------------------------------*/
  50.  
  51. /* debugger data structures */
  52.  
  53. typedef enum
  54. {
  55.   PTKEOK,
  56.   PTKEBREAK,
  57.   PTKESTRUCTEND,
  58.   PTKEDEBUGEND,
  59.   PTKEEXECUTE
  60. } ptketraversalstate;
  61.  
  62. typedef enum
  63. {
  64.   PTKEBREAKPT,
  65.   PTKETRACEPT,
  66.   PTKEWATCHPT,
  67.   PTKENOOP
  68. } ptkeoperationtype;
  69.  
  70. typedef struct ptksdebuginfo
  71. {
  72.   Pint debugstid;
  73.   Pint workingstid;
  74.   Pint debugelptr;
  75.   Pint workingelptr;
  76.   Pint elemcount;
  77.   Pelem_type eltype;
  78. } ptksdebuginfo;
  79.  
  80. typedef struct ptksdebugstack 
  81. {
  82.   ptksdebuginfo debuginfo;
  83.   struct ptksdebugstack *next;
  84. } ptksdebugstack;
  85.  
  86. typedef struct ptksexeclist
  87. {
  88.   Pint stid;
  89.   Pint numelems;
  90.   Pint_list bkpts;
  91.   Pint_list tcpts;
  92.   struct ptksexeclist *next;
  93. } ptksexeclist;
  94.  
  95. static ptksdebugstack *debugstack = NULL;
  96. static ptksexeclist *stpoints = NULL;
  97.  
  98. static ptksdebuginfo currentinfo;
  99. static Pint elembuffer;
  100. static Pint structbuffer;
  101. static Pint structwindow, topologywindow, contentwindow, terminalwindow;
  102. static Pint elementwindow;
  103. static ptkboolean elemposted = FALSE;
  104. static Pint dbgcount = 0;
  105. static Pint elemcontent, structcontent, currentcontent;
  106. static Pint contentlowlim, contentuplim;
  107. static Pint debugstackdepth = 0;
  108. static Pint debugwsid, debugrootstid;
  109. static Pint debugmenuid, windowmenuid, topologymenuid, contentmenuid;
  110. static Pint structmenuid, terminalmenuid, toptypemenuid;
  111. static Pint tslmenuid, tsl2menuid;
  112. static Pint rot3d1, rot3d2, rot2d1, rot2d2, rot1d;
  113. static Ppoint rot3d1pos, rot3d2pos, rot2d1pos, rot2d2pos, rot1dpos;
  114. static Pint topology, topologystid;
  115. static ptketraversalstate traversalstate;
  116. static Ppoint3 origin = {0.0, 0.0, 0.0};
  117. static Pint_list contentset;
  118. static Pfilter pickfilt;
  119. static Pint inclnames;
  120. static Plimit topview = {0.0, 1.0, 0.0, 1.0};
  121. static Pint curmenu = 0;
  122. static Pint curwindow = 0;
  123. static Pint lastcount, laststruct;
  124. static Pfloat devx, devy, devz;
  125. static Plimit echoarea;
  126.  
  127. /* debugger attributes */
  128. static Pint menucolourind = 0;
  129. static Pint windowcolourind = 0;
  130. static Pint menutextcolourind = 1;
  131. static Pint bannercolourind = 1;
  132. static Pint bannertextcolourind = 0;
  133. static Pint menutextfont = 1;
  134. static Pint windowtextfont = 1;
  135. static Pint backgroundcolourind = 0;
  136. static Pint tlcolourind = 1;
  137. static Pint brcolourind = 1;
  138. static Pint arrowcolourind = 0;
  139. static Pint arrowedgecolourind = 1;
  140.  
  141. /*--------------------------------------------------------------------------*/
  142.  
  143. static void ptk_transformlimits(C(Plimit *) lims, C(Pmatrix) mat)
  144. PreANSI(Plimit *lims)
  145. PreANSI(Pmatrix mat)
  146. {
  147.   Ppoint minbox, maxbox;
  148.  
  149.   minbox = ptk_point(lims->x_min, lims->y_min);
  150.   maxbox = ptk_point(lims->x_max, lims->y_max);
  151.   minbox = ptk_transform(mat, &minbox);
  152.   maxbox = ptk_transform(mat, &maxbox);
  153.   *lims = ptk_limit(minbox.x, maxbox.x, minbox.y, maxbox.y);
  154. }  /* ptk_transformlimits */
  155.  
  156. /*--------------------------------------------------------------------------*/
  157.  
  158. static void ptk_scalelimits(C(Ppoint *) scale, C(Plimit *) lims)
  159. PreANSI(Ppoint *scale)
  160. PreANSI(Plimit *lims)
  161. {
  162.   Ppoint minbox, maxbox;
  163.   Ppoint shift, size;
  164.   Pmatrix mat;
  165.  
  166.   minbox = ptk_point(lims->x_min, lims->y_min);
  167.   maxbox = ptk_point(lims->x_max, lims->y_max);
  168.   size = ptk_subv(&maxbox, &minbox);
  169.   shift = ptk_point(minbox.x + (size.x / 2.0), minbox.y + (size.y / 2.0));
  170.   shift = ptk_scalev(&shift, -1.0);
  171.   ptk_shift(&shift, PTYPE_REPLACE, mat);
  172.   ptk_scale(scale, PTYPE_POSTCONCAT, mat);
  173.   shift = ptk_scalev(&shift, -1.0);
  174.   ptk_shift(&shift, PTYPE_POSTCONCAT, mat);
  175.   ptk_transformlimits(lims, mat);
  176. }  /* ptk_scalelimits */
  177.  
  178. /*--------------------------------------------------------------------------*/
  179.  
  180. static void ptk_shiftlimits(C(Ppoint *) shift, C(Plimit *) lims)
  181. PreANSI(Ppoint *shift)
  182. PreANSI(Plimit *lims)
  183. {
  184.   Ppoint minbox, maxbox;
  185.   Pmatrix mat;
  186.  
  187.   minbox = ptk_point(lims->x_min, lims->y_min);
  188.   maxbox = ptk_point(lims->x_max, lims->y_max);
  189.   ptk_shift(shift, PTYPE_REPLACE, mat);
  190.   minbox = ptk_transform(mat, &minbox);
  191.   maxbox = ptk_transform(mat, &maxbox);
  192.   *lims = ptk_limit(minbox.x, maxbox.x, minbox.y, maxbox.y);
  193. }  /* ptk_shiftlimits */
  194.  
  195. /*--------------------------------------------------------------------------*/
  196.  
  197. static void ptk_stackdebug(C(ptksdebuginfo *) info)
  198. PreANSI(ptksdebuginfo *info)
  199. {
  200.   ptksdebugstack *stackitem;
  201.  
  202.   stackitem = (ptksdebugstack *)malloc(sizeof(ptksdebugstack));
  203.   stackitem->next = debugstack;
  204.   debugstack = stackitem;
  205.   stackitem->debuginfo = *info;
  206.   debugstackdepth++;
  207. }  /* ptk_stackdebug */
  208.  
  209. /*--------------------------------------------------------------------------*/
  210.  
  211. static void ptk_unstackdebug(C(ptksdebuginfo *) info)
  212. PreANSI(ptksdebuginfo *info)
  213. {
  214.   ptksdebugstack *stackitem;
  215.   
  216.   if (debugstack != NULL)
  217.   {
  218.     *info = debugstack->debuginfo;
  219.     stackitem = debugstack->next;
  220.     free(debugstack);
  221.     debugstack = stackitem;
  222.     debugstackdepth--;
  223.   }
  224. }  /* ptk_unstackdebug */
  225.  
  226. /*--------------------------------------------------------------------------*/
  227.  
  228. static ptkboolean findstpoint(C(Pint) stid, C(ptksexeclist **) list) 
  229. PreANSI(Pint stid)
  230. PreANSI(ptksexeclist **list)
  231. {
  232.   *list = stpoints;
  233.   while (*list != NULL)
  234.   {    
  235.     if ((*list)->stid == stid)
  236.     {
  237.       return TRUE;
  238.     }
  239.     else
  240.       *list = (*list)->next;
  241.   }
  242.   return FALSE;
  243. }  /* findstpoint */
  244.  
  245. /*--------------------------------------------------------------------------*/
  246.  
  247. static ptkboolean findbreakpoint(C(Pint) stid, C(Pint) elemptr)
  248. PreANSI(Pint stid)
  249. PreANSI(Pint elemptr)
  250. {
  251.   ptksexeclist *ptr;
  252.  
  253.   if (findstpoint(stid, &ptr))
  254.     if (inintlst(elemptr, &ptr->bkpts) != -1)
  255.       return TRUE;
  256.   return FALSE;
  257. }  /* findbreakpoint */
  258.  
  259. /*--------------------------------------------------------------------------*/
  260.  
  261. static ptkboolean findtracepoint(C(Pint) stid, C(Pint) elemptr)
  262. PreANSI(Pint stid)
  263. PreANSI(Pint elemptr)
  264. {
  265.   ptksexeclist *ptr;
  266.  
  267.   if (findstpoint(stid, &ptr))
  268.     if (inintlst(elemptr, &ptr->tcpts) != -1)
  269.       return TRUE;
  270.   return FALSE;
  271. }  /* findtracepoint */
  272.  
  273. /*--------------------------------------------------------------------------*/
  274.  
  275. static deletebreakpt(C(Pint) stid, C(Pint) elemptr)
  276. PreANSI(Pint stid)
  277. PreANSI(Pint elemptr)
  278. {
  279.   ptksexeclist *ptr;
  280.  
  281.   if (findstpoint(stid, &ptr))
  282.   {
  283.     pset_elem_ptr(0);
  284.     pset_elem_ptr_label(ptk_stringtoint("label", "struct$content-pts"));
  285. /*    poffset_elem_ptr(1); */
  286.     pset_elem_ptr_label(elemptr);
  287.     ptk_delelem(2);
  288.   }
  289. } /* deletebreakpt */
  290.  
  291. /*--------------------------------------------------------------------------*/
  292.  
  293. static deletetracept(C(Pint) stid, C(Pint) elemptr)
  294. PreANSI(Pint stid)
  295. PreANSI(Pint elemptr)
  296. {
  297.   ptksexeclist *ptr;
  298.  
  299.   if (findstpoint(stid, &ptr))
  300.   {
  301.     pset_elem_ptr(0);
  302.     pset_elem_ptr_label(ptk_stringtoint("label", "struct$content-pts"));
  303. /*    poffset_elem_ptr(1); */
  304.     pset_elem_ptr_label(elemptr + ptr->numelems);
  305.     ptk_delelem(2);
  306.   }
  307. } /* deletetracept */
  308.  
  309. /*--------------------------------------------------------------------------*/
  310.  
  311. static drawbreakpt(C(Pint) stid, C(Pint) elemptr)
  312. PreANSI(Pint stid)
  313. PreANSI(Pint elemptr)
  314. {
  315.   ptksexeclist *ptr;
  316.   Ppoint pts[5];
  317.   Pint ind, base;
  318.   Ppoint_list ptlist;
  319.  
  320.   if (findstpoint(stid, &ptr))
  321.   {
  322.     if ((ind = inintlst(elemptr, &ptr->bkpts)) != -1)
  323.     {
  324.       pset_elem_ptr(0);
  325.       pset_elem_ptr_label(ptk_stringtoint("label", "struct$content-pts"));
  326.       plabel(elemptr);
  327.       if (contentlowlim <= 0)
  328.         base = 0;
  329.       else
  330.         base = contentlowlim - 1;
  331.       pts[0] = ptk_point(0.025, 1.0 - (0.1 * 
  332.                         (ptr->bkpts.ints[ind] - base)) - 0.025);
  333.       pts[1] = ptk_point(0.675, pts[0].y);
  334.       pts[2] = ptk_point(0.675, pts[0].y - 0.05);
  335.       pts[3] = ptk_point(0.025, pts[2].y);
  336.       pts[4] = pts[0];
  337.       ptlist.num_points = 5;
  338.       ptlist.points = pts;
  339.       ppolyline(&ptlist);
  340.     }
  341.   }
  342. } /* drawbreakpt */
  343.  
  344. /*--------------------------------------------------------------------------*/
  345.  
  346. static drawtracept(C(Pint) stid, C(Pint) elemptr)
  347. PreANSI(Pint stid)
  348. PreANSI(Pint elemptr)
  349. {
  350.   ptksexeclist *ptr;
  351.   Ppoint pts[5];
  352.   Pint ind, base;
  353.   Ppoint_list ptlist;
  354.  
  355.   if (findstpoint(stid, &ptr))
  356.   {
  357.     if ((ind = inintlst(elemptr, &ptr->tcpts)) != -1)
  358.     {
  359.       plabel(elemptr + ptr->numelems);
  360.       if (contentlowlim <= 0)
  361.         base = 0;
  362.       else
  363.         base = contentlowlim - 1;
  364.       pts[0] = ptk_point(0.025, 1.0 - (0.1 * 
  365.                        (ptr->tcpts.ints[ind] - base)) - 0.025);
  366.       pts[1] = ptk_point(0.675, pts[0].y);
  367.       pts[2] = ptk_point(0.675, pts[0].y - 0.05);
  368.       pts[3] = ptk_point(0.025, pts[2].y);
  369.       pts[4] = pts[0];
  370.       ptlist.num_points = 5;
  371.       ptlist.points = pts;
  372.       ppolyline(&ptlist);
  373.     }
  374.   }
  375. } /* drawtracept */
  376.  
  377. /*--------------------------------------------------------------------------*/
  378.  
  379. static drawbreakpts(C(Pint) stid)
  380. PreANSI(Pint stid)
  381. {
  382.   ptksexeclist *ptr;
  383.   Pint i, base;
  384.   Ppoint pts[5];
  385.   Ppoint_list ptlist;
  386.  
  387.   pset_linetype(PLINE_DASH);
  388.   plabel(ptk_stringtoint("label", "struct$content-pts"));
  389.   if (findstpoint(stid, &ptr))
  390.   {
  391.     for (i = 0; i < ptr->bkpts.num_ints; i++)
  392.     {
  393.       plabel(ptr->bkpts.ints[i]);
  394.       if (contentlowlim <= 0)
  395.         base = 0;
  396.       else
  397.         base = contentlowlim - 1;
  398.       pts[0] = ptk_point(0.025, 1.0 - (0.1 * 
  399.                      (ptr->bkpts.ints[i] - base)) - 0.025);
  400.       pts[1] = ptk_point(0.675, pts[0].y);
  401.       pts[2] = ptk_point(0.675, pts[0].y - 0.05);
  402.       pts[3] = ptk_point(0.025, pts[2].y);
  403.       pts[4] = pts[0];
  404.       ptlist.num_points = 5;
  405.       ptlist.points = pts;
  406.       ppolyline(&ptlist);
  407.     }
  408.   }
  409. } /* drawbreakpts */
  410.  
  411. /*--------------------------------------------------------------------------*/
  412.  
  413. static drawtracepts(C(Pint) stid)
  414. PreANSI(Pint stid)
  415. {
  416.   ptksexeclist *ptr;
  417.   Pint i, base;
  418.   Ppoint pts[5];
  419.   Ppoint_list ptlist;
  420.  
  421.   pset_linetype(PLINE_DOT);
  422.   if (findstpoint(stid, &ptr))
  423.   {
  424.     for (i = 0; i < ptr->tcpts.num_ints; i++)
  425.     {
  426.       plabel(ptr->bkpts.ints[i] + ptr->numelems);     
  427.       if (contentlowlim <= 0)
  428.         base = 0;
  429.       else
  430.         base = contentlowlim - 1;
  431.       pts[0] = ptk_point(0.025, 1.0 - (0.1 * 
  432.                    (ptr->tcpts.ints[i] - base)) - 0.025);
  433.       pts[1] = ptk_point(0.675, pts[0].y);
  434.       pts[2] = ptk_point(0.675, pts[0].y - 0.05);
  435.       pts[3] = ptk_point(0.025, pts[2].y);
  436.       pts[4] = pts[0];
  437.       ptlist.num_points = 5;
  438.       ptlist.points = pts;
  439.       ppolyline(&ptlist);
  440.     }
  441.   }
  442. } /* drawtracepts */
  443.  
  444. /*--------------------------------------------------------------------------*/
  445.  
  446. static Pint getcopystid(C(Pint) stid)
  447. PreANSI(Pint stid)
  448. /* map from real structure id to copy id */
  449. {
  450.   char str[20];
  451.  
  452.   sprintf(str, "ptk$dbgst%d", stid);
  453.   return ptk_stringtoint("structureid", str); 
  454. }  /* getcopystid */
  455.  
  456. /*--------------------------------------------------------------------------*/
  457.  
  458. static void copynetwork()
  459. {
  460.   Pint i, j, tot, err, elptr, lstnum, stid, numelems;
  461.   char str[20];
  462.   Pint_list ids;
  463.   ptkselcontent elcont;
  464.   Pstore store;
  465.   ptkboolean finished;
  466.   Pelem_type eltype;
  467.   Psearch_status srchstat;
  468.  
  469.   ptk_inqstructnetids(debugrootstid, 0, &ids, &tot);
  470.   ids.ints = (Pint *)calloc(tot, sizeof(Pint));
  471.   ptk_inqstructnetids(debugrootstid, tot, &ids, &tot);
  472.   eltype = PELEM_EXEC_STRUCT;
  473.   pcreate_store(&err, &store);
  474.   for (i = 0; i < tot; i++)
  475.   {
  476.     sprintf(str, "ptk$dbgst%d", ids.ints[i]);
  477.     stid = ptk_stringtoint("structureid", str);
  478.     numelems = ptk_elemcount(ids.ints[i]);
  479.     ptk_openstruct(stid);
  480.     ptk_seteditmode(PEDIT_INSERT);
  481.     pcopy_all_elems_struct(ids.ints[i]);
  482.     ptk_unseteditmode();
  483.     pset_elem_ptr(0);
  484.     finished = FALSE;
  485.     ptk_seteditmode(PEDIT_REPLACE);
  486.     j = 0;
  487.     while ((!finished) && (j <= numelems))
  488.     {
  489.       ptk_findelemtype(&eltype, 1, PDIR_FORWARD, &srchstat, &elptr, &lstnum);
  490.       if (srchstat == PSEARCH_STATUS_SUCCESS)
  491.       {
  492.         pset_elem_ptr(elptr);
  493.         ptk_inqcurelemtypesizecontent(store, &err, &elcont);
  494.         pexec_struct(getcopystid(elcont.eldata->int_data));
  495.         poffset_elem_ptr(1);
  496.         j = elptr + 1;
  497.       }
  498.       else
  499.         finished = TRUE;
  500.     }
  501.     ptk_unseteditmode();
  502.     ptk_closestruct();
  503.   }
  504.   ptk_delstore(store);
  505.   free(ids.ints);
  506. }  /* copynetwork */
  507.  
  508. /*--------------------------------------------------------------------------*/
  509.  
  510. static Pint createnewstructid()
  511. /* working network */
  512. {
  513.   char str[20];
  514.  
  515.   sprintf(str, "ptk$wkdbgst%d", dbgcount);
  516.   dbgcount++;
  517.   return ptk_stringtoint("structureid", str);
  518. }  /* createnewstructid */
  519.  
  520. /*--------------------------------------------------------------------------*/
  521.  
  522. static void deletecopynetwork()
  523. /* delete the copy of the debugging structure network */
  524. {
  525.   Pint i, tot;
  526.   char str[20];
  527.   Pint_list ids;
  528.  
  529.   /* delete copy network */
  530.   sprintf(str, "ptk$dbgst%d", debugrootstid);
  531.   /* Implementation dependent if problems
  532.   ** with deleting structure networks e.g. DEC
  533.   */
  534. #ifndef VMS
  535.   pdel_struct_net(ptk_stringtoint("structureid", str), PFLAG_DEL);
  536. #endif
  537.   ptk_inqstructnetids(debugrootstid, 0, &ids, &tot);
  538.   ids.ints = (Pint *)calloc(tot, sizeof(Pint));
  539.   ptk_inqstructnetids(debugrootstid, tot, &ids, &tot);
  540.   for (i = 0; i < tot; i++)
  541.   {
  542.     sprintf(str, "ptk$dbgst%d", ids.ints[i]);
  543. /*
  544. #ifdef VMS
  545.     pdel_struct(ptk_stringtoint("structureid", str));
  546. #endif
  547. */
  548.     ptk_delstring("structureid", str);
  549.   }
  550.   free(ids.ints);
  551. }
  552.  
  553. /*--------------------------------------------------------------------------*/
  554.  
  555. static void clearstructid()
  556. /* Implementation dependent code.
  557. ** weird DEC PHIGS bug in DELETE STRUCTURE NETWORK,
  558. ** delete each structure in turn.
  559. */
  560. {
  561.   Pint i, tot;
  562.   char str[20];
  563.   Pint_list ids;
  564.   
  565.   /* delete working network */
  566.   sprintf(str, "ptk$wkdbgst%d", 0);
  567. #ifndef VMS
  568.   pdel_struct_net(ptk_stringtoint("structureid", str), PFLAG_DEL);
  569. #endif
  570.   for (i = 0; i < dbgcount; i++)
  571.   {
  572.     sprintf(str, "ptk$wkdbgst%d", i);
  573. /*
  574. #ifdef VMS
  575.     pdel_struct(ptk_stringtoint("structureid", str));
  576. #endif
  577. */
  578.     ptk_delstring("structureid", str);
  579.   }
  580. }  /* clearstructid */
  581.  
  582. /*--------------------------------------------------------------------------*/
  583.  
  584. static void setupdebugger(C(void))
  585. {
  586.   elembuffer = ptk_stringtoint("structureid", "ptk$dbgelembuffer");
  587.   elemcontent = ptk_stringtoint("structureid", "ptk$dbgelemcontent");
  588.   structcontent = ptk_stringtoint("structureid", "ptk$dbgstructcontent");
  589.   topology = ptk_stringtoint("topologyid", "ptk$dbgtopology"); 
  590. }  /* setupdebugger */
  591.  
  592. /*--------------------------------------------------------------------------*/
  593.  
  594. static void initialisedebugger(C(Pint) stid)
  595. PreANSI(Pint stid)
  596. {
  597.   Pint err;
  598.   Pint_list stlist;
  599.   
  600.   traversalstate = PTKEOK;
  601.   currentinfo.debugstid = stid;
  602.   currentinfo.debugelptr = currentinfo.workingelptr = 1;
  603.   currentinfo.elemcount = ptk_elemcount(stid);
  604.  
  605.   currentinfo.workingstid = createnewstructid();
  606.   stlist.num_ints = 1;
  607.   stlist.ints = &stid;
  608.   ptk_resetcamera(structwindow);
  609.   ptk_setcameraworld(structwindow, &stlist);
  610.   ptk_posttowindow(structwindow, currentinfo.workingstid);
  611.   ptk_createtopology(topology, stid, &err);
  612.   ptk_posttowindow(topologywindow, topology); 
  613.   ptk_settopologyhighlightnode(topology, stid);
  614.  
  615.   /* inquire topology name for picking */
  616.   ptk_inqtopologyname(topology, &inclnames, &err);
  617.  
  618.   contentset.num_ints = 1;
  619.   contentset.ints = &inclnames;
  620.   ptk_openstruct(structcontent);
  621.   padd_names_set(&contentset);
  622.   ptk_structcontent(debugwsid, stid, 0, PTKSTCTLIMIT, 1, 1, &err); 
  623.   currentcontent = stid;
  624.   premove_names_set(&contentset);
  625.   drawbreakpts(stid);
  626.   drawtracepts(stid);
  627.   ptk_closestruct();
  628.   /* set current structure content limits */
  629.   contentlowlim = 0;
  630.   contentuplim = PTKSTCTLIMIT;
  631.   ptk_posttowindow(contentwindow, structcontent);
  632.   ptk_setcontentviewrange(contentwindow, 0, 10);
  633.   if (currentinfo.elemcount > 0)
  634.   {
  635.     ptk_inqelemtype(stid, 1, &err, ¤tinfo.eltype);
  636.   }
  637.   else
  638.     currentinfo.eltype = PELEM_NIL;
  639.   ptk_openstruct(elembuffer);
  640.   ptk_copyelem(stid, 1);
  641.   ptk_closestruct();
  642.  
  643.   /* make topology and structure content pickable */
  644.   ptk_inqtopologystructid(topology, &topologystid, &err);
  645.   pickfilt.incl_set.num_ints = 1;
  646.   pickfilt.incl_set.ints = &inclnames;
  647.   pickfilt.excl_set.num_ints = 0;
  648.   pset_pick_filter(debugwsid, PICKDEV, &pickfilt);
  649.  
  650.   ptk_posttowindow(elementwindow, elemcontent);
  651.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  652. }  /* initialisedebugger */
  653.  
  654. /*--------------------------------------------------------------------------*/
  655.  
  656. static void cleardebugger(C(void))
  657. {  
  658.   pempty_struct(elembuffer);
  659.   pempty_struct(elemcontent);
  660.   pempty_struct(structcontent);
  661.   
  662.   /* clear windows */
  663.   ptk_unpostallfromwindow(structwindow);
  664.   ptk_unpostallfromwindow(topologywindow);
  665.   ptk_unpostallfromwindow(contentwindow);
  666.   ptk_unpostallfromwindow(elementwindow); 
  667.  
  668.   /* delete working network */
  669.   clearstructid();
  670.   dbgcount = 0;
  671.  
  672.   /* clear topology */
  673.   ptk_deltopology(topology);
  674.  
  675.   /* finish traversal */
  676. /*  if (traversalstate != PTKEDEBUGEND)
  677.     ptk_tsltraversetoend(); */
  678.  
  679.   /* reset debugger variables */
  680.   debugstack = NULL;
  681.   debugstackdepth = 0;
  682.   curmenu = 0;
  683.   curwindow = 0;
  684.   topview = ptk_limit(0.0, 1.0, 0.0, 1.0);
  685. }  /* cleardebugger */
  686.  
  687. /*--------------------------------------------------------------------------*/
  688.  
  689. static void restarttraversal()
  690. {
  691.   cleardebugger();
  692.   initialisedebugger(debugrootstid);
  693.   ptk_settslstart(getcopystid(debugrootstid), 0);
  694.   ptk_tsltraversenext();
  695. }  /* restarttraversal */
  696.  
  697. /*--------------------------------------------------------------------------*/
  698.  
  699. static void updateelembuffer(C(Pelem_type) eltype)
  700. PreANSI(Pelem_type eltype)
  701. {
  702.   ptk_openstruct(elembuffer);
  703.   ptk_seteditmode(PEDIT_REPLACE);
  704.   if (eltype == PELEM_EXEC_STRUCT)
  705.     ptk_copyelem(currentinfo.debugstid, currentinfo.debugelptr);
  706.   else
  707.     ptk_copyelem(getcopystid(currentinfo.debugstid), currentinfo.debugelptr);
  708.   ptk_unseteditmode();
  709.   ptk_closestruct();  
  710. }  /* updateelembuffer */
  711.  
  712. /*--------------------------------------------------------------------------*/
  713.  
  714. static void updatestructcontent(C(Pint) structid, C(Pint) elptr,
  715.                                 C(Pint) range1, C(Pint) range2)
  716. PreANSI(Pint structid)
  717. PreANSI(Pint elptr)
  718. PreANSI(Pint range1)
  719. PreANSI(Pint range2)
  720. {
  721.   Pint err;
  722.  
  723.   if (range1 < contentlowlim) 
  724.   {
  725.     contentlowlim = range1 - PTKSTCTLIMIT / 2;
  726.     contentuplim = range1 + PTKSTCTLIMIT / 2;
  727.   }
  728.   else
  729.   if (range2 > contentuplim)
  730.   {
  731.     contentlowlim = range2 - (PTKSTCTLIMIT / 2);
  732.     contentuplim = range2 + (PTKSTCTLIMIT / 2);
  733.   }
  734.   pempty_struct(structcontent);
  735.   ptk_openstruct(structcontent);
  736.   padd_names_set(&contentset);
  737.   ptk_structcontent(debugwsid, structid, contentlowlim, contentuplim,
  738.                     elptr, 1, &err);
  739.   currentcontent = structid;
  740.   premove_names_set(&contentset);
  741.   drawbreakpts(structid);
  742.   drawtracepts(structid);
  743.   ptk_closestruct();    
  744.   ptk_posttowindow(contentwindow, structcontent);
  745.   ptk_setcontentviewrange(contentwindow, range1, range2);
  746. }  /* updatestructcontent */
  747.  
  748. /*--------------------------------------------------------------------------*/
  749.  
  750. static void do_next_elem(C(void))
  751. {
  752.   Pint err, count, structid, elptr, lenstr;
  753.   ptkselcontent elcont;
  754.   char name[80];
  755.   ptksdebuginfo temp;
  756.   Pstore store;
  757.  
  758.   ptk_tsltraversenext();
  759.   traversalstate = PTKEOK;
  760.   if (findtracepoint(currentinfo.debugstid, currentinfo.debugelptr))
  761.   {
  762.     ptk_inttostring("structureid", currentinfo.debugstid, 80, name, &lenstr);
  763.     if (lenstr == 0)
  764.       sprintf(name, "%d\0", currentinfo.debugstid); 
  765.     ptk_printfterminal(terminalwindow, 
  766.                    "tracepoint reached at structure %s, element %d.\n",
  767.                    name, currentinfo.debugelptr);
  768.     ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  769.   }
  770.   if (currentinfo.eltype == PELEM_EXEC_STRUCT)
  771.   {
  772.     traversalstate = PTKEEXECUTE;
  773.     temp = currentinfo;
  774.     temp.debugelptr++;
  775.     temp.workingelptr++;
  776.     ptk_stackdebug(&temp);    
  777.     pcreate_store(&err, &store);
  778.     ptk_inqelemtypesizecontent(elembuffer, 1, store, &err, &elcont);
  779.     currentinfo.debugstid = elcont.eldata->int_data;
  780.     ptk_delstore(store);
  781.     currentinfo.debugelptr = 1;
  782.     currentinfo.elemcount = ptk_elemcount(currentinfo.debugstid);
  783.     
  784.     if (currentinfo.elemcount > 0)
  785.     {
  786.       ptk_inqelemtype(currentinfo.debugstid, currentinfo.debugelptr, 
  787.                       &err, ¤tinfo.eltype);
  788.       updateelembuffer(currentinfo.eltype);
  789.     }
  790.     else
  791.       currentinfo.eltype = PELEM_NIL;
  792.  
  793.     /* create new working structure */
  794.     ptk_openstruct(currentinfo.workingstid);
  795.     currentinfo.workingstid = createnewstructid();
  796.     currentinfo.workingelptr = 1;
  797.     pexec_struct(currentinfo.workingstid);
  798.     ptk_closestruct();
  799.     /* update topology */
  800.     ptk_settopologyhighlightnode(topology, currentinfo.debugstid);
  801.     /* update structure content */
  802.     contentlowlim = 0;
  803.     contentuplim = PTKSTCTLIMIT;
  804.     updatestructcontent(currentinfo.debugstid, 1, 0, 10);
  805.   }
  806.   else
  807.   {
  808.     if (currentinfo.eltype != PELEM_NIL)
  809.     {
  810.       ptk_openstruct(currentinfo.workingstid);
  811.       ptk_copyelem(elembuffer, 1);
  812.       ptk_closestruct();
  813.     }
  814.  
  815.     currentinfo.workingelptr++;
  816.     currentinfo.debugelptr++;
  817.  
  818.     if (currentinfo.elemcount < currentinfo.debugelptr)
  819.     {
  820.       if ((currentinfo.elemcount == currentinfo.debugelptr - 1) ||
  821.           (currentinfo.elemcount == currentinfo.debugelptr - 2))
  822.       {
  823.         lastcount = currentinfo.elemcount;
  824.         laststruct = currentinfo.debugstid;
  825.       }
  826.       /* reached end of structure */
  827.       traversalstate = PTKESTRUCTEND;
  828.       if (debugstack == NULL)
  829.         traversalstate = PTKEDEBUGEND;
  830.       else
  831.       {
  832.         do
  833.     {
  834.           ptk_unstackdebug(¤tinfo);
  835.         } while ((currentinfo.debugelptr > currentinfo.elemcount) &&
  836.                  (debugstack != NULL));
  837.         if ((debugstack != NULL) || 
  838.             (currentinfo.debugelptr < currentinfo.elemcount))
  839.     {
  840.           count = 10;
  841.           elptr = currentinfo.debugelptr;
  842.           structid = currentinfo.debugstid;
  843.         }
  844.         else
  845.     {
  846.           count = elptr = lastcount;
  847.           structid = laststruct;
  848.         }
  849.         /* update topology */
  850.         ptk_settopologyhighlightnode(topology, structid);
  851.         /* update structure content */
  852.         contentlowlim = count - (PTKSTCTLIMIT / 2);
  853.         contentuplim = count + (PTKSTCTLIMIT / 2);
  854.         updatestructcontent(structid, elptr, count - 10, count);
  855.       }
  856.     }
  857.     else
  858.     {
  859.       if (currentcontent != currentinfo.debugstid)
  860.       {
  861.         contentlowlim = currentinfo.debugelptr - (PTKSTCTLIMIT / 2);
  862.         contentuplim = currentinfo.debugelptr + (PTKSTCTLIMIT / 2);
  863.         updatestructcontent(currentinfo.debugstid, currentinfo.debugelptr,
  864.                      currentinfo.debugelptr, currentinfo.debugelptr + 10);
  865.       }
  866.       else
  867.         ptk_setstructcontentelemptr(structcontent, currentinfo.debugelptr);
  868.     }
  869.     if (currentinfo.elemcount >= currentinfo.debugelptr)
  870.     {
  871.       ptk_inqelemtype(currentinfo.debugstid, currentinfo.debugelptr, 
  872.                       &err, ¤tinfo.eltype);
  873.       updateelembuffer(currentinfo.eltype);
  874.     }
  875.     else
  876.       currentinfo.eltype = PELEM_NIL;
  877.   }
  878.   if (findbreakpoint(currentinfo.debugstid, currentinfo.debugelptr))
  879.     traversalstate = PTKEBREAK;
  880. }  /* do_next_elem */
  881.  
  882. /*--------------------------------------------------------------------------*/
  883.  
  884. static void do_step()
  885. {
  886.   Pint startstid;
  887.  
  888.   if (traversalstate == PTKEDEBUGEND)
  889.     restarttraversal();
  890.   if (currentinfo.eltype == PELEM_EXEC_STRUCT)
  891.   {
  892.     pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  893.     startstid = currentinfo.workingstid;
  894.     do
  895.     {
  896.       if (currentinfo.eltype == PELEM_EXEC_STRUCT)
  897.       {
  898.         do_next_elem();
  899.         ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  900.       }
  901.       else
  902.         do_next_elem();
  903.     } while ((traversalstate != PTKEBREAK) && 
  904.              (currentinfo.workingstid != startstid));
  905.   }
  906.   else
  907.     do_next_elem();
  908.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  909. }  /* do_step */
  910.  
  911. /*--------------------------------------------------------------------------*/
  912.  
  913. static void do_stepreturn()
  914. {
  915.   Pint startstid;
  916.  
  917.   if (traversalstate == PTKEDEBUGEND)
  918.     restarttraversal();
  919.   if (debugstack != NULL)
  920.   {
  921.     startstid = debugstack->debuginfo.debugstid;
  922.     do
  923.     {
  924.       if (currentinfo.eltype == PELEM_EXEC_STRUCT)
  925.       {
  926.         do_next_elem();
  927.         ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  928.       }
  929.       else
  930.         do_next_elem();
  931.     } while ((traversalstate != PTKEBREAK) && 
  932.              (currentinfo.debugstid != startstid));
  933.   }
  934.   else
  935.   {
  936.     /* at the root structure */
  937.     do
  938.     {
  939.       if (currentinfo.eltype == PELEM_EXEC_STRUCT)
  940.       {
  941.         do_next_elem();
  942.         ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  943.       }
  944.       else
  945.         do_next_elem();
  946.     } while ((traversalstate == PTKEBREAK) && (traversalstate == PTKEDEBUGEND));
  947.   }
  948.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  949. }  /* do_stepreturn */
  950.  
  951. /*--------------------------------------------------------------------------*/
  952.  
  953. static void do_stepinto()
  954. {
  955.   if (traversalstate == PTKEDEBUGEND)
  956.     restarttraversal();
  957.   if (currentinfo.eltype == PELEM_EXEC_STRUCT)
  958.     do_next_elem();
  959.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  960. }  /* stepinto */
  961.  
  962. /*--------------------------------------------------------------------------*/
  963.  
  964. static void do_go()
  965. {
  966.   Pint ws, devnum; 
  967.   Pin_class class;
  968.  
  969.   pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  970.   if (traversalstate == PTKEDEBUGEND)
  971.     restarttraversal();
  972.   pset_loc_mode(debugwsid, LOCDEV, POP_EVENT, PSWITCH_NO_ECHO);
  973.   do
  974.   {
  975.     if (currentinfo.eltype == PELEM_EXEC_STRUCT)
  976.     {
  977.       do_next_elem();
  978.       ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  979.     }
  980.     else
  981.       do_next_elem();
  982.     pawait_event(0.0, &ws, &class, &devnum); 
  983.     if ((ws == debugwsid) && (class == PIN_LOC))
  984.       traversalstate = PTKEBREAK; 
  985.   } while ((traversalstate != PTKEBREAK) && (traversalstate != PTKEDEBUGEND));
  986.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  987. }  /* do_go */
  988.  
  989. /*--------------------------------------------------------------------------*/
  990.  
  991. static void do_examine(C(Pint) stid, C(Pint) elemptr)
  992. PreANSI(Pint stid)
  993. PreANSI(Pint elemptr)
  994. {
  995.   Pint err;
  996.   ptkboolean graphics;
  997.   Pint_list stlist;
  998.  
  999.   pempty_struct(elemcontent);
  1000.   ptk_openstruct(elemcontent);
  1001.   graphics = ptk_elemcontent(stid, elemptr, terminalwindow, &err);
  1002.   ptk_closestruct();
  1003.   if (graphics)
  1004.   { 
  1005.     pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  1006.     stlist.num_ints = 1;
  1007.     stlist.ints = &elemcontent;
  1008.     ptk_resetcamera(elementwindow);
  1009.     ptk_setcameraworld(elementwindow, &stlist);
  1010.     if (!elemposted)
  1011.     {
  1012.       ptk_postwindow(elementwindow);
  1013.       elemposted = TRUE;
  1014.     }
  1015.   }
  1016.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1017. }  /* do_examine */
  1018.  
  1019. /*--------------------------------------------------------------------------*/
  1020.  
  1021. static void do_setbreakpoint(C(Pint) stid, C(Pint) elemptr)
  1022. PreANSI(Pint stid)
  1023. PreANSI(Pint elemptr)
  1024. {
  1025.   ptksexeclist *stptr, *newptr;
  1026.  
  1027.   if (!findstpoint(stid, &stptr))
  1028.   {
  1029.     newptr = (ptksexeclist *)malloc(sizeof(ptksexeclist));
  1030.     newptr->next = stpoints;
  1031.     stpoints = newptr;
  1032.     newptr->stid = stid;
  1033.     newptr->numelems = ptk_elemcount(stid);  
  1034.     newptr->tcpts.num_ints = 0;
  1035.     newptr->tcpts.ints = (Pint *)calloc(50, sizeof(Pint));
  1036.     newptr->bkpts.num_ints = 1;
  1037.     newptr->bkpts.ints = (Pint *)calloc(50, sizeof(Pint));
  1038.     newptr->bkpts.ints[0] = elemptr;
  1039.     ptk_openstruct(structcontent);
  1040.     drawbreakpt(stid, elemptr);
  1041.     ptk_closestruct();
  1042.   }
  1043.   else
  1044.   if (inintlst(elemptr, &stptr->bkpts) == -1)
  1045.   {
  1046.     stptr->bkpts.ints[stptr->bkpts.num_ints++] = elemptr;
  1047.     ptk_openstruct(structcontent);
  1048.     drawbreakpt(stid, elemptr);
  1049.     ptk_closestruct();
  1050.   }
  1051. }  /* do_setbreakpoint */
  1052.  
  1053. /*--------------------------------------------------------------------------*/
  1054.  
  1055. static void do_settracepoint(C(Pint) stid, C(Pint) elemptr)
  1056. PreANSI(Pint stid)
  1057. PreANSI(Pint elemptr)
  1058. {
  1059.   ptksexeclist *stptr, *newptr;
  1060.  
  1061.   if (!findstpoint(stid, &stptr))
  1062.   {
  1063.     newptr = (ptksexeclist *)malloc(sizeof(ptksexeclist));
  1064.     newptr->next = stpoints;
  1065.     stpoints = newptr;
  1066.     newptr->stid = stid;  
  1067.     newptr->numelems = ptk_elemcount(stid);
  1068.     newptr->tcpts.num_ints = 1;
  1069.     newptr->tcpts.ints = (Pint *)calloc(50, sizeof(Pint));
  1070.     newptr->bkpts.num_ints = 0;
  1071.     newptr->bkpts.ints = (Pint *)calloc(50, sizeof(Pint));
  1072.     newptr->tcpts.ints[0] = elemptr;
  1073.     ptk_openstruct(structcontent);
  1074.     drawtracept(stid, elemptr);
  1075.     ptk_closestruct();
  1076.   }
  1077.   else
  1078.   if (inintlst(elemptr, &stptr->tcpts) == -1)
  1079.   {
  1080.     stptr->tcpts.ints[stptr->tcpts.num_ints++] = elemptr;
  1081.     ptk_openstruct(structcontent);
  1082.     drawtracept(stid, elemptr);
  1083.     ptk_closestruct();
  1084.   }
  1085. }  /* do_settracepoint */
  1086.  
  1087. /*--------------------------------------------------------------------------*/
  1088.  
  1089. static void do_cancelbreakpoint(C(Pint) stid, C(Pint) elemptr)
  1090. PreANSI(Pint stid)
  1091. PreANSI(Pint elemptr)
  1092. {
  1093.   ptksexeclist *stptr;
  1094.   Pint i, ind;
  1095.  
  1096.   if (findstpoint(stid, &stptr))
  1097.   {
  1098.     if ((ind = inintlst(elemptr, &stptr->bkpts)) != -1)
  1099.     {
  1100.       for (i = ind; i < stptr->bkpts.num_ints; i++)
  1101.         stptr->bkpts.ints[i] = stptr->bkpts.ints[i + 1];
  1102.       stptr->bkpts.num_ints--;
  1103.       ptk_openstruct(structcontent);
  1104.       deletebreakpt(stid, elemptr);
  1105.       ptk_closestruct();
  1106.     }
  1107.   }
  1108. }  /* do_cancelbreakpoint */
  1109.  
  1110. /*--------------------------------------------------------------------------*/
  1111.  
  1112. static void do_canceltracepoint(C(Pint) stid, C(Pint) elemptr)
  1113. PreANSI(Pint stid)
  1114. PreANSI(Pint elemptr)
  1115. {
  1116.   ptksexeclist *stptr;
  1117.   Pint i, ind;
  1118.  
  1119.   if (findstpoint(stid, &stptr))
  1120.   {
  1121.     if ((ind = inintlst(elemptr, &stptr->tcpts)) != -1)
  1122.     {
  1123.       for (i = ind; i < stptr->tcpts.num_ints; i++)
  1124.         stptr->tcpts.ints[i] = stptr->tcpts.ints[i + 1];
  1125.       stptr->tcpts.num_ints--;
  1126.       ptk_openstruct(structcontent);
  1127.       deletetracept(stid, elemptr);
  1128.       ptk_closestruct();
  1129.     }
  1130.   }
  1131. }  /* do_canceltracepoint */
  1132.  
  1133. /*--------------------------------------------------------------------------*/
  1134.  
  1135. static void makemenus(C(void))
  1136. {
  1137.   Pint err;
  1138.   Ppoint topleft;
  1139.   Ppoint box, size;
  1140.  
  1141.   /* debugger menu */
  1142.   debugmenuid = ptk_stringtoint("menuid", "ptk$debugmenu"); 
  1143.   box = ptk_point(0.1, 0.05);
  1144.   topleft = ptk_point(0.0, 1.0);
  1145.   ptk_createboxmenu(debugmenuid, &topleft, &box);
  1146.   ptk_setboxmenuattrs(debugwsid, debugmenuid, PPATH_DOWN, menutextfont,
  1147.                     menutextcolourind, menucolourind,
  1148.                     bannercolourind, tlcolourind, brcolourind,
  1149.                     menutextcolourind, menucolourind, menucolourind);
  1150.  
  1151.   ptk_createtextmenuitem(debugmenuid, "go", 1, PEDIT_INSERT, &err);
  1152.   ptk_createtextmenuitem(debugmenuid, "step", 2, PEDIT_INSERT, &err);
  1153.   ptk_createtextmenuitem(debugmenuid, "step in", 3, PEDIT_INSERT, &err);
  1154.   ptk_createtextmenuitem(debugmenuid, "examine", 4, PEDIT_INSERT, &err);
  1155.   ptk_createtextmenuitem(debugmenuid, "deposit", 5, PEDIT_INSERT, &err);
  1156.   ptk_createtextmenuitem(debugmenuid, "phinter", 6, PEDIT_INSERT, &err);
  1157.   ptk_createtextmenuitem(debugmenuid, "TSL", 7, PEDIT_INSERT, &err);
  1158.   ptk_createtextmenuitem(debugmenuid, "restart", 8, PEDIT_INSERT, &err);
  1159.   ptk_createtextmenuitem(debugmenuid, "refresh", 9, PEDIT_INSERT, &err);
  1160.   ptk_createtextmenuitem(debugmenuid, "exit", 10, PEDIT_INSERT, &err);
  1161.  
  1162.   /* window menu */
  1163.   windowmenuid = ptk_stringtoint("menuid", "ptk$windowmenu"); 
  1164.   box = ptk_point(0.1, 0.05);
  1165.   topleft = ptk_point(0.0, 1.0);
  1166.   ptk_createboxmenu(windowmenuid, &topleft, &box);
  1167.   ptk_setboxmenuattrs(debugwsid, windowmenuid, PPATH_DOWN, menutextfont,
  1168.                     menutextcolourind, menucolourind,
  1169.                     bannercolourind, tlcolourind, brcolourind,
  1170.                     menutextcolourind, menucolourind, menucolourind);
  1171.  
  1172.   ptk_createtextmenuitem(windowmenuid, "close", 1, PEDIT_INSERT, &err);
  1173.   ptk_createtextmenuitem(windowmenuid, "move", 2, PEDIT_INSERT, &err);
  1174.   ptk_createtextmenuitem(windowmenuid, "resize", 3, PEDIT_INSERT, &err);
  1175.   ptk_createtextmenuitem(windowmenuid, "front", 4, PEDIT_INSERT, &err);
  1176.   ptk_createtextmenuitem(windowmenuid, "back", 5, PEDIT_INSERT, &err);
  1177.  
  1178.   /* topology menu */
  1179.   topologymenuid = ptk_stringtoint("menuid", "ptk$topologymenu"); 
  1180.   box = ptk_point(0.1, 0.05);
  1181.   topleft = ptk_point(0.0, 1.0);
  1182.   ptk_createboxmenu(topologymenuid, &topleft, &box);
  1183.   ptk_setboxmenuattrs(debugwsid, topologymenuid, PPATH_DOWN, menutextfont,
  1184.                     menutextcolourind, menucolourind,
  1185.                     bannercolourind, tlcolourind, brcolourind,
  1186.                     menutextcolourind, menucolourind, menucolourind);
  1187.  
  1188.   ptk_createtextmenuitem(topologymenuid, "type", 1, PEDIT_INSERT, &err);
  1189.   ptk_createtextmenuitem(topologymenuid, "view", 2, PEDIT_INSERT, &err);
  1190.   ptk_createtextmenuitem(topologymenuid, "tidy node", 3, PEDIT_INSERT, &err);
  1191.   ptk_createtextmenuitem(topologymenuid, "tidy group", 4, PEDIT_INSERT, &err);
  1192.   ptk_createtextmenuitem(topologymenuid, "store", 5, PEDIT_INSERT, &err);
  1193.   ptk_createtextmenuitem(topologymenuid, "restore", 6, PEDIT_INSERT, &err);
  1194.  
  1195.   /* content menu */
  1196.   contentmenuid = ptk_stringtoint("menuid", "ptk$contentmenu"); 
  1197.   box = ptk_point(0.1, 0.05);
  1198.   topleft = ptk_point(0.0, 1.0);
  1199.   ptk_createboxmenu(contentmenuid, &topleft, &box);
  1200.   ptk_setboxmenuattrs(debugwsid, contentmenuid, PPATH_DOWN, menutextfont,
  1201.                     menutextcolourind, menucolourind,
  1202.                     bannercolourind, tlcolourind, brcolourind,
  1203.                     menutextcolourind, menucolourind, menucolourind);
  1204.  
  1205.   ptk_createtextmenuitem(contentmenuid, "set break", 1, PEDIT_INSERT, &err);
  1206.   ptk_createtextmenuitem(contentmenuid, "set trace", 2, PEDIT_INSERT, &err);
  1207.   ptk_createtextmenuitem(contentmenuid, "cancel brk", 3, PEDIT_INSERT, &err);
  1208.   ptk_createtextmenuitem(contentmenuid, "cancel trc", 4, PEDIT_INSERT, &err);
  1209.   ptk_createtextmenuitem(contentmenuid, "scroll", 5, PEDIT_INSERT, &err);
  1210.  
  1211.   /* structure menu */
  1212.   structmenuid = ptk_stringtoint("menuid", "ptk$structmenu"); 
  1213.   box = ptk_point(0.1, 0.05);
  1214.   topleft = ptk_point(0.0, 1.0);
  1215.   ptk_createboxmenu(structmenuid, &topleft, &box);
  1216.   ptk_setboxmenuattrs(debugwsid, structmenuid, PPATH_DOWN, menutextfont,
  1217.                     menutextcolourind, menucolourind,
  1218.                     bannercolourind, tlcolourind, brcolourind,
  1219.                     menutextcolourind, menucolourind, menucolourind);
  1220.  
  1221.   ptk_createtextmenuitem(structmenuid, "camera", 1, PEDIT_INSERT, &err);
  1222.   ptk_createtextmenuitem(structmenuid, "reset", 2, PEDIT_INSERT, &err);
  1223.  
  1224.   /* terminal menu */
  1225.   terminalmenuid = ptk_stringtoint("menuid", "ptk$terminalmenu"); 
  1226.   box = ptk_point(0.1, 0.05);
  1227.   topleft = ptk_point(0.0, 1.0);
  1228.   ptk_createboxmenu(terminalmenuid, &topleft, &box); 
  1229.   ptk_setboxmenuattrs(debugwsid, terminalmenuid, PPATH_DOWN, menutextfont,
  1230.                     menutextcolourind, menucolourind,
  1231.                     bannercolourind, tlcolourind, brcolourind,
  1232.                     menutextcolourind, menucolourind, menucolourind);
  1233.  
  1234.   ptk_createtextmenuitem(terminalmenuid, "scroll", 1, PEDIT_INSERT, &err);
  1235.   ptk_createtextmenuitem(terminalmenuid, "clear", 2, PEDIT_INSERT, &err);
  1236.  
  1237.   /* topology type menu */
  1238.   toptypemenuid = ptk_stringtoint("menuid", "ptk$toptypemenu"); 
  1239.   box = ptk_point(0.1, 0.05);
  1240.   topleft = ptk_point(0.0, 1.0);
  1241.   ptk_createboxmenu(toptypemenuid, &topleft, &box);
  1242.   ptk_setboxmenuattrs(debugwsid, toptypemenuid, PPATH_DOWN, menutextfont,
  1243.                     menutextcolourind, menucolourind,
  1244.                     bannercolourind, tlcolourind, brcolourind,
  1245.                     menutextcolourind, menucolourind, menucolourind);
  1246.  
  1247.   ptk_createtextmenuitem(toptypemenuid, "box", 1, PEDIT_INSERT, &err);
  1248.   ptk_createtextmenuitem(toptypemenuid, "struct", 2, PEDIT_INSERT, &err);
  1249.   ptk_createtextmenuitem(toptypemenuid, "structnet", 3, PEDIT_INSERT, &err);
  1250.  
  1251.   /* TSL menu */
  1252.   tslmenuid = ptk_stringtoint("menuid", "ptk$tslmenu"); 
  1253.   box = ptk_point(0.1, 0.05);
  1254.   topleft = ptk_point(0.0, 1.0);
  1255.   ptk_createboxmenu(tslmenuid, &topleft, &box);
  1256.   ptk_setboxmenuattrs(debugwsid, tslmenuid, PPATH_DOWN, menutextfont,
  1257.                     menutextcolourind, menucolourind,
  1258.                     bannercolourind, tlcolourind, brcolourind,
  1259.                     menutextcolourind, menucolourind, menucolourind);
  1260.  
  1261.   ptk_createtextmenuitem(tslmenuid, "line", 1, PEDIT_INSERT, &err);
  1262.   ptk_createtextmenuitem(tslmenuid, "marker", 2, PEDIT_INSERT, &err);
  1263.   ptk_createtextmenuitem(tslmenuid, "interior", 3, PEDIT_INSERT, &err);
  1264.   ptk_createtextmenuitem(tslmenuid, "edge", 4, PEDIT_INSERT, &err);
  1265.   ptk_createtextmenuitem(tslmenuid, "text", 5, PEDIT_INSERT, &err);
  1266.   ptk_createtextmenuitem(tslmenuid, "annotext", 6, PEDIT_INSERT, &err);
  1267.  
  1268.   /* TSL2 menu */
  1269.   tsl2menuid = ptk_stringtoint("menuid", "ptk$tsl2menu"); 
  1270.   box = ptk_point(0.1, 0.05);
  1271.   topleft = ptk_point(0.0, 1.0);
  1272.   ptk_createboxmenu(tsl2menuid, &topleft, &box); 
  1273.   ptk_setboxmenuattrs(debugwsid, tsl2menuid, PPATH_DOWN, menutextfont,
  1274.                     menutextcolourind, menucolourind,
  1275.                     bannercolourind, tlcolourind, brcolourind,
  1276.                     menutextcolourind, menucolourind, menucolourind);
  1277.  
  1278.   ptk_createtextmenuitem(tsl2menuid, "char", 1, PEDIT_INSERT, &err);
  1279.   ptk_createtextmenuitem(tsl2menuid, "ctm", 2, PEDIT_INSERT, &err);
  1280.   ptk_createtextmenuitem(tsl2menuid, "nameset", 3, PEDIT_INSERT, &err);
  1281.   ptk_createtextmenuitem(tsl2menuid, "ids", 4, PEDIT_INSERT, &err);
  1282.   ptk_createtextmenuitem(tsl2menuid, "asf", 5, PEDIT_INSERT, &err);
  1283.   ptk_createtextmenuitem(tsl2menuid, "bbox", 6, PEDIT_INSERT, &err);
  1284.  
  1285.   /* rotators */
  1286.   rot3d1 = ptk_stringtoint("menuid", "ptk$rotator3d1"); 
  1287.   rot3d2 = ptk_stringtoint("menuid", "ptk$rotator3d2"); 
  1288.   rot2d1 = ptk_stringtoint("menuid", "ptk$rotator2d1"); 
  1289.   rot2d2 = ptk_stringtoint("menuid", "ptk$rotator2d2"); 
  1290.   rot1d = ptk_stringtoint("menuid", "ptk$rotator1d"); 
  1291.   rot3d1pos = ptk_point(0.15, 0.88);
  1292.   rot3d2pos = ptk_point(0.15, 0.66);
  1293.   rot2d1pos = ptk_point(0.1, 0.88);
  1294.   rot2d2pos = ptk_point(0.1, 0.66);
  1295.   rot1dpos = ptk_point(0.1, 0.66);
  1296.   size = ptk_point(0.3, 0.2);
  1297.   ptk_createrotator(debugwsid, rot3d1, PTKETHREED, &size, "rotator",
  1298.                     0.02);
  1299.   ptk_setrotatorattrs(debugwsid, rot3d1, windowtextfont,
  1300.                       bannertextcolourind, arrowcolourind, 
  1301.                       arrowedgecolourind, 
  1302.                       windowcolourind, bannercolourind,
  1303.                       bannercolourind, tlcolourind, brcolourind);
  1304.   ptk_createrotator(debugwsid, rot3d2, PTKETHREED, &size, "rotator",
  1305.                     0.02);
  1306.   ptk_setrotatorattrs(debugwsid, rot3d2, windowtextfont,
  1307.                       bannertextcolourind, arrowcolourind, 
  1308.                       arrowedgecolourind, 
  1309.                       windowcolourind, bannercolourind,
  1310.                       bannercolourind, tlcolourind, brcolourind);
  1311.   size = ptk_point(0.2, 0.2);
  1312.   ptk_createrotator(debugwsid, rot2d1, PTKETWOD, &size, "rotator",
  1313.                     0.02);
  1314.   ptk_setrotatorattrs(debugwsid, rot2d1, windowtextfont,
  1315.                       bannertextcolourind, arrowcolourind, 
  1316.                       arrowedgecolourind, 
  1317.                       windowcolourind, bannercolourind,
  1318.                       bannercolourind, tlcolourind, brcolourind);
  1319.   ptk_createrotator(debugwsid, rot2d2, PTKETWOD, &size, "rotator",
  1320.                     0.02);
  1321.   ptk_setrotatorattrs(debugwsid, rot2d2, windowtextfont,
  1322.                       bannertextcolourind, arrowcolourind, 
  1323.                       arrowedgecolourind, 
  1324.                       windowcolourind, bannercolourind,
  1325.                       bannercolourind, tlcolourind, brcolourind);
  1326.   ptk_createrotator(debugwsid, rot1d, PTKEONED, &size, "rotator",
  1327.                     0.02);
  1328.   ptk_setrotatorattrs(debugwsid, rot1d, windowtextfont,
  1329.                       bannertextcolourind, arrowcolourind, 
  1330.                       arrowedgecolourind, 
  1331.                       windowcolourind, bannercolourind,
  1332.                       bannercolourind, tlcolourind, brcolourind);
  1333.   ptk_setmenuposition(rot3d1, &rot3d1pos);
  1334.   ptk_setmenuposition(rot3d2, &rot3d2pos);
  1335.   ptk_setmenuposition(rot2d1, &rot2d1pos);
  1336.   ptk_setmenuposition(rot2d2, &rot2d2pos);
  1337.   ptk_setmenuposition(rot1d, &rot1dpos);
  1338. }  /* makemenus */
  1339.  
  1340. /*--------------------------------------------------------------------------*/
  1341.  
  1342. static void do_moverotator(C(Pint) menuid)
  1343. PreANSI(Pint menuid)
  1344. {
  1345.   Ppoint *pos, inpos;
  1346.   Pint initview, view_index, tot, err;
  1347.   Pin_status status;
  1348.   Plimit echo;
  1349.   Ploc_data locrec;
  1350.   char title[30];
  1351.  
  1352.   pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_UQUM);
  1353.   ptk_inqrotatortitle(menuid, 30, title, &tot, &err);
  1354.   ptk_setrotatortitle(menuid, "MOVE");
  1355.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1356.   if (menuid == rot3d1)
  1357.     pos = &rot3d1pos;
  1358.   else
  1359.   if (menuid == rot3d2)
  1360.     pos = &rot3d2pos;
  1361.   else
  1362.   if (menuid == rot2d1)
  1363.     pos = &rot2d1pos;
  1364.   else
  1365.   if (menuid == rot2d2)
  1366.     pos = &rot2d2pos;
  1367.   else
  1368.   if (menuid == rot1d)
  1369.     pos = &rot1dpos;
  1370.   initview = 0;
  1371.   echo = ptk_limit(0.0, devx, 0.0, devy);
  1372.   /* Implementation dependent - locator device data record */
  1373. #ifdef HP
  1374.   locrec.pets.pet_r1.loc_colr_ind = 1;
  1375. #endif
  1376.   pinit_loc(debugwsid, LOCDEV, initview, pos, 1, &echo, &locrec);
  1377.   pset_loc_mode(debugwsid, LOCDEV, POP_REQ, PSWITCH_ECHO);
  1378.   preq_loc(debugwsid, LOCDEV, &status, &view_index, &inpos);
  1379.   if (status == PIN_STATUS_OK)
  1380.   {
  1381.     *pos = inpos;
  1382.     ptk_setmenuposition(menuid, pos);
  1383.   }
  1384.   ptk_setrotatortitle(menuid, title);
  1385. }  /* do_moverotator */
  1386.  
  1387. /*--------------------------------------------------------------------------*/
  1388.  
  1389. static void do_pickelem(C(Pint *) stid, C(Pint *) elemptr)
  1390. PreANSI(Pint *stid)
  1391. PreANSI(Pint *elemptr)
  1392. {
  1393.   Ppick_path pick;
  1394.   Pin_status status;
  1395.   Ppick_path_elem pathel[10];
  1396.   Pfilter contentfilt;
  1397.  
  1398.   contentfilt.incl_set = contentset;
  1399.   contentfilt.excl_set = pickfilt.excl_set;
  1400.   *stid = currentcontent;
  1401.   pset_pick_filter(debugwsid, PICKDEV, &contentfilt);
  1402.   pset_loc_mode(debugwsid, LOCDEV, POP_REQ, PSWITCH_ECHO);
  1403.   pset_pick_mode(debugwsid, PICKDEV, POP_REQ, PSWITCH_ECHO);  
  1404.   pick.path_list = pathel;
  1405.   preq_pick(debugwsid, PICKDEV, 10, &status, &pick);
  1406.   if (status == PIN_STATUS_OK)
  1407.     *elemptr = pick.path_list[1].pick_id;  
  1408.   else
  1409.     *elemptr = -1;
  1410. } /* do_pickelem */
  1411.  
  1412. /*--------------------------------------------------------------------------*/
  1413.  
  1414. static void do_scrollterminal()
  1415. {
  1416.   ptkboolean quit;
  1417.   Pint ws, devnum;
  1418.   Pin_class class;
  1419.   Ppoint position;
  1420.   Pint view_index;
  1421.   ptksgeneralinput geninput;
  1422.   ptksmenuoutput menuoutput;
  1423.   Ploc_data locrec;
  1424.   Ptext_path direction;
  1425.   Pint numlines, maxlines, maxcolumns, txfont, txcolour, err;
  1426.  
  1427.   ptk_setrotatortitle(rot1d, "scroll terminal");
  1428.   ptk_postmenu(debugwsid, rot1d);
  1429.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1430.   pset_loc_mode(debugwsid, LOCDEV, POP_EVENT, PSWITCH_ECHO);
  1431.   quit = FALSE;
  1432.   ptk_inqterminaldata(terminalwindow, &maxlines, &maxcolumns, &txfont,
  1433.                       &txcolour, &err);
  1434.   do
  1435.   {
  1436.     pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  1437.     pawait_event(0.0, &ws, &class, &devnum);
  1438.     if ((class == PIN_LOC) && (ws == debugwsid))
  1439.     {
  1440.       pget_loc(&view_index, &position);
  1441.       geninput.inputclass = PIN_LOC;
  1442.       geninput.ptkugeninput.locpoint = position;
  1443.       if (ptk_scanmenus(debugwsid, &geninput, &menuoutput))
  1444.       {
  1445.         pset_loc_mode(debugwsid, LOCDEV, POP_REQ, PSWITCH_ECHO);
  1446.         if (menuoutput.menuid == rot1d)
  1447.     {
  1448.           if (menuoutput.itemnum == 0)
  1449.             do_moverotator(rot1d);
  1450.           else
  1451.       {
  1452.             switch (menuoutput.itemnum)
  1453.         {
  1454.           case 1:
  1455.                 direction = PPATH_DOWN;
  1456.                 numlines = (Pint)(menuoutput.value.y * (Pfloat)maxlines);
  1457.                 break;
  1458.  
  1459.           case 2:
  1460.                 direction = PPATH_UP;
  1461.                 numlines = (Pint)((1.0 - menuoutput.value.y) * 
  1462.                                   (Pfloat)maxlines);
  1463.                 break;
  1464.         }
  1465.             ptk_scrollterminal(terminalwindow, direction, numlines);
  1466.             ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1467.           }
  1468.     }
  1469.         pset_loc_mode(debugwsid, LOCDEV, POP_EVENT, PSWITCH_ECHO);
  1470.       }
  1471.       else
  1472.       {
  1473.         quit = TRUE;
  1474.       }
  1475.     }
  1476.   } while (!quit);
  1477.   ptk_unpostmenu(debugwsid, rot1d);
  1478. } /* do_scrollterminal */
  1479.  
  1480. /*--------------------------------------------------------------------------*/
  1481.  
  1482. static void do_scrollcontent()
  1483. {
  1484.   ptkboolean quit;
  1485.   Pint ws, devnum;
  1486.   Pin_class class;
  1487.   Ppoint position;
  1488.   Pint view_index, eptr;
  1489.   ptksgeneralinput geninput;
  1490.   ptksmenuoutput menuoutput;
  1491.   Ploc_data locrec;
  1492.   Ptext_path direction;
  1493.   Pint numlines, range1, range2, maxrange2, err, scrollfactor;
  1494.  
  1495.   ptk_setrotatortitle(rot1d, "scroll content");
  1496.   ptk_postmenu(debugwsid, rot1d);
  1497.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1498.   pset_loc_mode(debugwsid, LOCDEV, POP_EVENT, PSWITCH_ECHO);
  1499.   quit = FALSE;
  1500.   maxrange2 = ptk_elemcount(currentcontent);
  1501.   ptk_inqcontentviewrange(contentwindow, &range1, &range2, &err);
  1502.   scrollfactor = range2 - range1;
  1503.   if (scrollfactor < 10)
  1504.     scrollfactor = 10;
  1505.   do
  1506.   {
  1507.     pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  1508.     pawait_event(0.0, &ws, &class, &devnum);
  1509.     if ((class == PIN_LOC) && (ws == debugwsid))
  1510.     {
  1511.       pget_loc(&view_index, &position);
  1512.       geninput.inputclass = PIN_LOC;
  1513.       geninput.ptkugeninput.locpoint = position;
  1514.       if (ptk_scanmenus(debugwsid, &geninput, &menuoutput))
  1515.       {
  1516.         pset_loc_mode(debugwsid, LOCDEV, POP_REQ, PSWITCH_ECHO);
  1517.         if (menuoutput.menuid == rot1d)
  1518.     {
  1519.           if (menuoutput.itemnum == 0)
  1520.             do_moverotator(rot1d);
  1521.           else
  1522.       {
  1523.             switch (menuoutput.itemnum)
  1524.         {
  1525.           case 1:
  1526.                 numlines = (Pint)(menuoutput.value.y * (Pfloat)scrollfactor);
  1527.                 if (range1 - numlines >= 0)
  1528.             {
  1529.                   range1 -= numlines;
  1530.                   range2 -= numlines;
  1531.                 }
  1532.                 else
  1533.             {
  1534.                   range1 = 0;
  1535.                   range2 = scrollfactor;
  1536.                 }
  1537.                 break;
  1538.  
  1539.           case 2:
  1540.                 numlines = (Pint)((1.0 - menuoutput.value.y) * 
  1541.                                 (Pfloat)scrollfactor);
  1542.                 if (range2 + numlines <= maxrange2)
  1543.             {
  1544.                   range1 += numlines;
  1545.                   range2 += numlines;
  1546.                 }
  1547.                 else
  1548.             {
  1549.                   range1 = maxrange2 - scrollfactor;
  1550.                   range2 = maxrange2;
  1551.                 }
  1552.                 break;
  1553.         }
  1554.             if ((range1 - scrollfactor) < contentlowlim) 
  1555.             {
  1556.               contentlowlim = range1 - (PTKSTCTLIMIT / 2);
  1557.               contentuplim = range1 + (PTKSTCTLIMIT / 2);
  1558.               eptr = -1;
  1559.               if (currentcontent == currentinfo.debugstid)
  1560.                 eptr = currentinfo.debugelptr;
  1561.               updatestructcontent(currentcontent, eptr, range1, range2);
  1562.             }
  1563.             else
  1564.             if ((range2 + scrollfactor) > contentuplim)
  1565.             {
  1566.               contentlowlim = range2 - (PTKSTCTLIMIT / 2);
  1567.               contentuplim = range2 + (PTKSTCTLIMIT / 2);
  1568.               eptr = -1;
  1569.               if (currentcontent == currentinfo.debugstid)
  1570.                 eptr = currentinfo.debugelptr;
  1571.               updatestructcontent(currentcontent, eptr, range1, range2);
  1572.             }
  1573.             else
  1574.               ptk_setcontentviewrange(contentwindow, range1, range2);
  1575.             ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1576.           }
  1577.     }
  1578.         pset_loc_mode(debugwsid, LOCDEV, POP_EVENT, PSWITCH_ECHO);
  1579.       }
  1580.       else
  1581.       {
  1582.         quit = TRUE;
  1583.       }
  1584.     }
  1585.   } while (!quit);
  1586.   ptk_unpostmenu(debugwsid, rot1d);
  1587. } /* do_scrollcontent */
  1588.  
  1589. /*--------------------------------------------------------------------------*/
  1590.  
  1591. static void do_zoompantopology(C(ptksmenuoutput *) menuout, C(Plimit *) window)
  1592. PreANSI(ptksmenuoutput *menuout)
  1593. PreANSI(Plimit *window)
  1594. {
  1595.   Ppoint shift, scale;
  1596.   Pfloat movefactor;
  1597.  
  1598.   movefactor = (topview.x_max - topview.x_min) / 2.0;
  1599.   switch (menuout->itemnum)
  1600.   {
  1601.     case 1: /* decrease y */
  1602.       shift = ptk_point(0.0, (menuout->value.y * movefactor));
  1603.       ptk_shiftlimits(&shift, window);
  1604.       break;
  1605.  
  1606.     case 2: /* increase y */
  1607.       shift = ptk_point(0.0, -((1.0 - menuout->value.y) * movefactor));
  1608.       ptk_shiftlimits(&shift, window);
  1609.       break;
  1610.  
  1611.     case 3: /* increase x */
  1612.       shift = ptk_point(-((1.0 - menuout->value.x) * movefactor), 0.0);
  1613.       ptk_shiftlimits(&shift, window);
  1614.       break;
  1615.  
  1616.     case 4: /* decrease x */
  1617.       shift = ptk_point((menuout->value.x * movefactor), 0.0);
  1618.       ptk_shiftlimits(&shift, window);
  1619.       break;
  1620.  
  1621.     case 5: /* decrease x and y */
  1622.       scale = ptk_point(1.0 - (menuout->value.y * 0.1), 
  1623.                         1.0 - (menuout->value.y * 0.1));
  1624.       ptk_scalelimits(&scale, window);
  1625.       break;
  1626.  
  1627.     case 6: /* increase x and y */
  1628.       scale = ptk_point(1.0 + (menuout->value.y * 0.1), 
  1629.                         1.0 + (menuout->value.y * 0.1));
  1630.       ptk_scalelimits(&scale, window);
  1631.       break;
  1632.   }
  1633. }  /* do_zoompantopology */
  1634.  
  1635. /*--------------------------------------------------------------------------*/
  1636.  
  1637. static void do_topologyview()
  1638. {
  1639.   ptkboolean quit;
  1640.   Pint ws, devnum;
  1641.   Pin_class class;
  1642.   Ppoint position;
  1643.   Pint view_index;  
  1644.   ptksgeneralinput geninput;
  1645.   ptksmenuoutput menuoutput;
  1646.   Ploc_data locrec;
  1647.  
  1648.   ptk_setrotatortitle(rot3d1, "zoom + pan");
  1649.   ptk_postmenu(debugwsid, rot3d1);
  1650.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1651.   pset_loc_mode(debugwsid, LOCDEV, POP_EVENT, PSWITCH_ECHO);
  1652.   quit = FALSE;
  1653.   do
  1654.   {
  1655.     pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  1656.     pawait_event(0.0, &ws, &class, &devnum);
  1657.     if ((class == PIN_LOC) && (ws == debugwsid))
  1658.     {
  1659.       pget_loc(&view_index, &position);
  1660.       geninput.inputclass = PIN_LOC;
  1661.       geninput.ptkugeninput.locpoint = position;
  1662.       if (ptk_scanmenus(debugwsid, &geninput, &menuoutput))
  1663.       {
  1664.         pset_loc_mode(debugwsid, LOCDEV, POP_REQ, PSWITCH_ECHO);
  1665.         if (menuoutput.menuid == rot3d1)
  1666.     {
  1667.           if (menuoutput.itemnum == 0)
  1668.             do_moverotator(rot3d1);
  1669.           else
  1670.       {
  1671.             do_zoompantopology(&menuoutput, &topview);
  1672.             ptk_settopologyviewarea(topologywindow, &topview);
  1673.           }
  1674.           ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1675.     }
  1676.         pset_loc_mode(debugwsid, LOCDEV, POP_EVENT, PSWITCH_ECHO);
  1677.       }
  1678.       else
  1679.       {
  1680.         quit = TRUE;
  1681.       }
  1682.     }
  1683.   } while (!quit);
  1684.   ptk_unpostmenu(debugwsid, rot3d1);
  1685. }  /* do_topologyview */
  1686.  
  1687. /*--------------------------------------------------------------------------*/
  1688.  
  1689. static void do_spincamera(C(Pint) windid, C(ptksmenuoutput *) menuout)
  1690. PreANSI(Pint windid)
  1691. PreANSI(ptksmenuoutput *menuout)
  1692. {
  1693.   Pfloat angle;
  1694.  
  1695.   switch (menuout->itemnum)
  1696.   {
  1697.     case 1:
  1698.       angle = menuout->value.y * 10.0;
  1699.       ptk_rotatepositionxaxis(windid, angle);
  1700.       break;
  1701.  
  1702.     case 2:
  1703.       angle = (1.0 - menuout->value.y) * 10.0;
  1704.       ptk_rotatepositionxaxis(windid, -angle);
  1705.       break;
  1706.  
  1707.     case 3:
  1708.       angle = (1.0 - menuout->value.x) * 10.0;
  1709.       ptk_rotatepositionyaxis(windid, angle);
  1710.       break;
  1711.  
  1712.     case 4:
  1713.       angle = menuout->value.x * 10.0;
  1714.       ptk_rotatepositionyaxis(windid, -angle);
  1715.       break;
  1716.  
  1717.     case 5:
  1718.       angle = menuout->value.y * 10.0;
  1719.       ptk_rotatecameraupvector(windid, angle);
  1720.       break;
  1721.  
  1722.     case 6:
  1723.       angle = menuout->value.y * 10.0;
  1724.       ptk_rotatecameraupvector(windid, -angle);
  1725.       break;
  1726.   }
  1727. }  /* do_spincamera */
  1728.  
  1729. /*--------------------------------------------------------------------------*/
  1730.  
  1731. static void do_zoompancamera(C(Pint) windid, C(ptksmenuoutput *) menuout)
  1732. PreANSI(Pint windid)
  1733. PreANSI(ptksmenuoutput *menuout)
  1734. {
  1735.   Pfloat zoomfactor, xsize, ysize;
  1736.   Ppoint3 shift;
  1737.   Plimit3 limits;
  1738.   Pint err;
  1739.  
  1740.   ptk_inqcameralimits(windid, &limits, &err);
  1741.   xsize = limits.x_max - limits.x_min;
  1742.   ysize = limits.y_max - limits.y_min;
  1743.   xsize /= 2.0;
  1744.   ysize /= 2.0;
  1745.   switch (menuout->itemnum)
  1746.   {
  1747.     case 1:
  1748.       shift = ptk_point3(0.0, menuout->value.y * ysize, 0.0);
  1749.       ptk_shiftcamera(windid, &shift);
  1750.       break;
  1751.  
  1752.     case 2:
  1753.       shift = ptk_point3(0.0, -(1.0 - menuout->value.y) * ysize, 0.0);
  1754.       ptk_shiftcamera(windid, &shift); 
  1755.       break;
  1756.  
  1757.     case 3:
  1758.       shift = ptk_point3(-(1.0 - menuout->value.x) * xsize, 0.0, 0.0);
  1759.       ptk_shiftcamera(windid, &shift);
  1760.       break;
  1761.  
  1762.     case 4:
  1763.       shift = ptk_point3(menuout->value.x * xsize, 0.0, 0.0);
  1764.       ptk_shiftcamera(windid, &shift);
  1765.       break;
  1766.  
  1767.     case 5:
  1768.       zoomfactor = menuout->value.y * 0.1;
  1769.       ptk_scaleviewwindow(windid, 1.0 - zoomfactor);
  1770.       break;
  1771.  
  1772.     case 6:
  1773.       zoomfactor = menuout->value.y * 0.1;
  1774.       ptk_scaleviewwindow(windid, 1.0 + zoomfactor);
  1775.       break;
  1776.   }
  1777. }  /* do_zoompancamera */
  1778.  
  1779. /*--------------------------------------------------------------------------*/
  1780.  
  1781. static void camerainterface(C(Pint) windid)
  1782. PreANSI(Pint windid)
  1783. {
  1784.   ptkboolean cameraquit;
  1785.   Pint ws, devnum;
  1786.   Pin_class class;
  1787.   Ppoint position;
  1788.   Pint view_index;
  1789.   ptksgeneralinput geninput;
  1790.   ptksmenuoutput menuoutput;
  1791.   Ploc_data locrec;
  1792.  
  1793.   ptk_setrotatortitle(rot3d1, "rotate");
  1794.   ptk_setrotatortitle(rot3d2, "zoom + pan");
  1795.   ptk_postmenu(debugwsid, rot3d1);
  1796.   ptk_postmenu(debugwsid, rot3d2);
  1797.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1798.   pset_loc_mode(debugwsid, LOCDEV, POP_EVENT, PSWITCH_ECHO);
  1799.   cameraquit = FALSE;
  1800.   do
  1801.   {
  1802.     pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  1803.     pawait_event(0.0, &ws, &class, &devnum);
  1804.     if ((class == PIN_LOC) && (ws == debugwsid))
  1805.     {
  1806.       pget_loc(&view_index, &position);
  1807.       geninput.inputclass = PIN_LOC;
  1808.       geninput.ptkugeninput.locpoint = position;
  1809.       if (ptk_scanmenus(debugwsid, &geninput, &menuoutput))
  1810.       {
  1811.         pset_loc_mode(debugwsid, LOCDEV, POP_REQ, PSWITCH_ECHO);
  1812.         if (menuoutput.menuid == rot3d1)
  1813.     {
  1814.           if (menuoutput.itemnum == 0)
  1815.             do_moverotator(rot3d1);
  1816.           else
  1817.             do_spincamera(windid, &menuoutput);
  1818.           ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1819.     }
  1820.         else
  1821.         if (menuoutput.menuid == rot3d2)
  1822.     {
  1823.           if (menuoutput.itemnum == 0)
  1824.             do_moverotator(rot3d2);
  1825.           else
  1826.             do_zoompancamera(windid, &menuoutput);
  1827.           ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1828.     }
  1829.         pset_loc_mode(debugwsid, LOCDEV, POP_EVENT, PSWITCH_ECHO);
  1830.       }
  1831.       else
  1832.       {
  1833.         cameraquit = TRUE;
  1834.       }
  1835.     }
  1836.   } while (!cameraquit);
  1837.   ptk_unpostmenu(debugwsid, rot3d1);
  1838.   ptk_unpostmenu(debugwsid, rot3d2);
  1839. }  /* camerainterface */
  1840.  
  1841. /*--------------------------------------------------------------------------*/
  1842.  
  1843. static void do_debugmenu(C(Pint) menuitem, C(Ppoint *) pos)
  1844. PreANSI(Pint menuitem)
  1845. PreANSI(Ppoint *pos)
  1846. {
  1847.   Ppoint pos2;
  1848.   Pint stid, elemptr, err;
  1849.   Pelem_type eltype;
  1850.   Pint_list stlist;
  1851.  
  1852.   switch (menuitem)
  1853.   {
  1854.     case 1: /* go */ 
  1855.       ptk_unpostallmenu(debugwsid);
  1856.       curmenu = 0;
  1857.       do_go();
  1858.       break;
  1859.  
  1860.     case 2: /* step */
  1861.       do_step();
  1862.       break;
  1863.  
  1864.     case 3: /* step into */
  1865.       pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  1866.       do_stepinto();
  1867.       break;
  1868.  
  1869.     case 4: /* examine */
  1870.       do_examine(elembuffer, 1);
  1871.       break;
  1872.  
  1873.     case 5: /* deposit */
  1874.       if (traversalstate != PTKEDEBUGEND)
  1875.       {
  1876.         ptk_openstruct(getcopystid(currentinfo.debugstid));
  1877.         pset_elem_ptr(currentinfo.workingelptr);
  1878.         ptk_inqcurelemtype(&err, &eltype);
  1879.         if (eltype != PELEM_EXEC_STRUCT)
  1880.     {
  1881.           ptk_seteditmode(PEDIT_REPLACE);
  1882.           ptk_readelem(debugwsid, &echoarea, eltype);
  1883.  
  1884.           ptk_closestruct();
  1885.           ptk_openstruct(elembuffer);
  1886.           ptk_copyelem(getcopystid(currentinfo.debugstid), 
  1887.                        currentinfo.workingelptr);
  1888.           ptk_unseteditmode();
  1889.         }
  1890.         ptk_closestruct();  
  1891.       }
  1892.       else
  1893.         ptk_writelnterminal(terminalwindow, "At end of structure network.");
  1894.       ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1895.       break;
  1896.  
  1897.     case 6: /* phinter */
  1898.       ptk_callphinter();
  1899.       break;
  1900.  
  1901.     case 7: /* tsl menu */ 
  1902.       ptk_setmenuposition(tslmenuid, pos);
  1903.       ptk_postmenu(debugwsid, tslmenuid);
  1904.       pos2 = *pos;
  1905.       pos2.x += 0.1;
  1906.       ptk_setmenuposition(tsl2menuid, &pos2);
  1907.       ptk_postmenu(debugwsid, tsl2menuid);
  1908.       ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1909.       break;
  1910.  
  1911.     case 8: /* restart */
  1912.       pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  1913.       restarttraversal();
  1914.       ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  1915.       break;
  1916.  
  1917.     case 9: /* refresh */
  1918.       pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  1919.       predraw_all_structs(debugwsid, PFLAG_ALWAYS);
  1920.       break;
  1921.   }  
  1922. }  /* do_debugmenu */
  1923.  
  1924. /*--------------------------------------------------------------------------*/
  1925.  
  1926. static void do_windowmenu(C(Pint) menuitem, C(ptkswindowoutput *) windoutput)
  1927. PreANSI(Pint menuitem)
  1928. PreANSI(ptkswindowoutput *windoutput)
  1929. {
  1930.   ptkboolean closed;
  1931.   Plimit echo;
  1932.   Ploc_data locrec;
  1933.   Ppoint initpt, position;
  1934.   Pint initview, view_index;
  1935.   Pint err;
  1936.   Pin_status status;
  1937.  
  1938.   if (windoutput->windowarea == PTKEWINDOWICON)
  1939.     closed = TRUE;
  1940.   else
  1941.     closed = FALSE;
  1942.   echo = ptk_limit(0.0, devx, 0.0, devy);
  1943.   switch (menuitem)
  1944.   {
  1945.     case 1: /* open/close */
  1946.       if (closed)
  1947.         ptk_openwindow(windoutput->windowid);
  1948.       else
  1949.         ptk_closewindow(windoutput->windowid);
  1950.       break;
  1951.  
  1952.     case 2: /* move */
  1953.       {
  1954.         initview = 0;
  1955.         if (closed)
  1956.           ptk_inqiconposition(windoutput->windowid, &initpt, &err);
  1957.         else
  1958.           ptk_inqwindowposition(windoutput->windowid, &initpt, &err);
  1959.         /* Implementation dependent - locator device data record */
  1960. #ifdef HP
  1961.   locrec.pets.pet_r1.loc_colr_ind = 1;
  1962. #endif
  1963.         pinit_loc(debugwsid, LOCDEV, initview, &initpt, 1, &echo, &locrec);
  1964.         pset_loc_mode(debugwsid, LOCDEV, POP_REQ, PSWITCH_ECHO);
  1965.         preq_loc(debugwsid, LOCDEV, &status, &view_index, &position);
  1966.         if (status == PIN_STATUS_OK)
  1967.           if (closed)
  1968.             ptk_seticonposition(windoutput->windowid, &position);
  1969.           else
  1970.       {
  1971.             pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  1972.             ptk_setwindowposition(windoutput->windowid, &position);
  1973.           }
  1974.       }
  1975.       break;
  1976.  
  1977.     case 3: /* resize */
  1978.       {
  1979.         Pfloat width, height;
  1980.         Ppoint size;
  1981.  
  1982.         initview = 0;
  1983.         if (closed)
  1984.           ptk_inqiconposition(windoutput->windowid, &initpt, &err);
  1985.         else
  1986.           ptk_inqwindowposition(windoutput->windowid, &initpt, &err);
  1987.  
  1988.         /* implementation dependent code
  1989.         ** to produce rubber banding rectangle (locator pet)
  1990.         */
  1991. #ifdef SUN
  1992.         locrec.pets.pet_u5.line_bundle.type = PLINE_SOLID;
  1993.         locrec.pets.pet_u5.line_bundle.width = 1.0;
  1994.         locrec.pets.pet_u5.line_bundle.colr_ind = 1;
  1995.         pinit_loc(debugwsid, LOCDEV, initview, &initpt, -5, &echo, &locrec);
  1996. #endif
  1997. #ifdef HP
  1998.         locrec.pets.pet_r5.line_fill_ctrl_flag = PFLAG_LINE;
  1999.         locrec.pets.pet_r5.attrs.line_attrs.type_asf = PASF_INDIV;
  2000.         locrec.pets.pet_r5.attrs.line_attrs.width_asf = PASF_INDIV;
  2001.         locrec.pets.pet_r5.attrs.line_attrs.colr_ind_asf = PASF_INDIV;
  2002.         locrec.pets.pet_r5.attrs.line_attrs.bundle.type = PLINE_SOLID;
  2003.         locrec.pets.pet_r5.attrs.line_attrs.bundle.width = 1.0;      
  2004.         locrec.pets.pet_r5.attrs.line_attrs.bundle.colr_ind = 1;
  2005.         pinit_loc(debugwsid, LOCDEV, initview, &initpt, 5, &echo, &locrec);
  2006. #endif
  2007. #ifdef PEXSI
  2008.         pinit_loc(debugwsid, LOCDEV, initview, &initpt, 1, &echo, &locrec);
  2009. #endif
  2010.         pset_loc_mode(debugwsid, LOCDEV, POP_REQ, PSWITCH_ECHO);
  2011.         preq_loc(debugwsid, LOCDEV, &status, &view_index, &position);
  2012.         if (status == PIN_STATUS_OK)
  2013.     {
  2014.           width = PTKMAX(initpt.x, position.x) - PTKMIN(initpt.x, position.x);
  2015.           height = PTKMAX(initpt.y, position.y) - 
  2016.                    PTKMIN(initpt.y, position.y);
  2017.           width *= 2.0;
  2018.           height *= 2.0;
  2019.           size = ptk_point(width, height);
  2020.           if (closed)
  2021.             ptk_seticonsize(windoutput->windowid, &size);
  2022.           else
  2023.       {
  2024.             pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  2025.             ptk_setwindowsize(windoutput->windowid, &size);
  2026.           }
  2027.         }
  2028.         /* Implementation dependent - locator device data record */
  2029. #ifdef HP
  2030.         locrec.pets.pet_r1.loc_colr_ind = 1;
  2031. #endif
  2032.         pinit_loc(debugwsid, LOCDEV, initview, &initpt, 1, &echo, &locrec);
  2033.       }      
  2034.       break;
  2035.  
  2036.     case 4: /* front */
  2037.       pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  2038.       ptk_frontwindow(windoutput->windowid);
  2039.       break;
  2040.  
  2041.     case 5: /* back */
  2042.       pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  2043.       ptk_backwindow(windoutput->windowid);
  2044.       break;
  2045.   }  
  2046.   ptk_unpostmenu(debugwsid, windowmenuid);
  2047.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  2048. }  /* do_windowmenu */
  2049.  
  2050. /*--------------------------------------------------------------------------*/
  2051.  
  2052. static void do_topologymenu(C(Pint) menuitem, C(Ppoint *) pos)
  2053. PreANSI(Pint menuitem)
  2054. PreANSI(Ppoint *pos)
  2055. {
  2056.   Ppick_data pickrec;
  2057.   Ploc_data locrec;
  2058.   FILE *fileptr;
  2059.   char filename[80];
  2060.   Pint namelen;
  2061.  
  2062.   switch (menuitem)
  2063.   {
  2064.     case 1: /* type */
  2065.       ptk_setmenuposition(toptypemenuid, pos);
  2066.       ptk_postmenu(debugwsid, toptypemenuid);
  2067.       break;
  2068.  
  2069.     case 2: /* view */
  2070.       ptk_unpostmenu(debugwsid, topologymenuid);
  2071.       do_topologyview();
  2072.       curmenu = 0;
  2073.       break;
  2074.  
  2075.     case 3: /* tidy single */
  2076.       /* implementation dependent - pick and locator data records */
  2077. /*
  2078. #ifdef VMS
  2079.       pickrec.pets.pet_r1.aperature = 0.01;
  2080. #endif
  2081. */
  2082.       ptk_setwindowtraninputpri(topologywindow, 0, PPRI_HIGHER);
  2083.       ptk_tidytopology(debugwsid, topology, PTKESINGLE, PICKDEV, 1, &pickrec, 
  2084.                        LOCDEV, 1, &locrec); 
  2085.       ptk_setwindowtraninputpri(topologywindow, 0, PPRI_LOWER);
  2086.       ptk_unpostmenu(debugwsid, topologymenuid);
  2087.       curmenu = 0;
  2088.       break;
  2089.  
  2090.     case 4: /* tidy group */
  2091.       /* implementation dependent - pick and locator data records */
  2092. /*
  2093. #ifdef VMS
  2094.       pickrec.pets.pet_r1.aperature = 0.01;
  2095. #endif
  2096. */
  2097.       ptk_setwindowtraninputpri(topologywindow, 0, PPRI_HIGHER);
  2098.       ptk_tidytopology(debugwsid, topology, PTKEGROUP, PICKDEV, 1, &pickrec, 
  2099.                        LOCDEV, 1, &locrec); 
  2100.       ptk_setwindowtraninputpri(topologywindow, 0, PPRI_LOWER);
  2101.       ptk_unpostmenu(debugwsid, topologymenuid);
  2102.       curmenu = 0;
  2103.       break;
  2104.  
  2105.     case 5: /* store */
  2106.       ptk_readstring(debugwsid, "", "Input filename >", &echoarea,
  2107.                      80, filename, &namelen);
  2108.       if ((fileptr = fopen(filename, "w+")) != NULL)
  2109.       {
  2110.         rewind(fileptr);
  2111.         ptk_storetopologylayout(fileptr, topology);
  2112.         fclose(fileptr);
  2113.         ptk_printfterminal(terminalwindow, "topology layout stored in %s.\n",
  2114.                            filename);
  2115.       }
  2116.       break;
  2117.  
  2118.     case 6: /* restore */
  2119.       ptk_readstring(debugwsid, "", "Input filename >", &echoarea,
  2120.                      80, filename, &namelen);
  2121.       if ((fileptr = fopen(filename, "r")) != NULL)
  2122.       {
  2123.         rewind(fileptr);
  2124.         ptk_restoretopologylayout(fileptr, topology);
  2125.         fclose(fileptr);
  2126.         ptk_printfterminal(terminalwindow, 
  2127.                            "topology layout restored from %s.\n", filename);
  2128.       }
  2129.       break;
  2130.   }
  2131.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);  
  2132. }  /* do_topologymenu */
  2133.  
  2134. /*--------------------------------------------------------------------------*/
  2135.  
  2136. static void do_contentmenu(C(Pint) menuitem)
  2137. PreANSI(Pint menuitem)
  2138. {
  2139.   Pint stid, elemptr;
  2140.  
  2141.   switch (menuitem)
  2142.   {
  2143.     case 1: /* set break */
  2144.       do_pickelem(&stid, &elemptr);
  2145.       if (elemptr != -1)
  2146.         do_setbreakpoint(stid, elemptr);
  2147.       ptk_unpostmenu(debugwsid, contentmenuid);
  2148.       break;
  2149.  
  2150.     case 2: /* set trace */
  2151.       do_pickelem(&stid, &elemptr);
  2152.       if (elemptr != -1)
  2153.         do_settracepoint(stid, elemptr);
  2154.       ptk_unpostmenu(debugwsid, contentmenuid);
  2155.       break;
  2156.  
  2157.     case 3: /* cancel break */
  2158.       do_pickelem(&stid, &elemptr);
  2159.       if (elemptr != -1)
  2160.         do_cancelbreakpoint(stid, elemptr);
  2161.       ptk_unpostmenu(debugwsid, contentmenuid);
  2162.       break;
  2163.  
  2164.     case 4: /* cancel trace */
  2165.       do_pickelem(&stid, &elemptr);
  2166.       if (elemptr != -1)
  2167.         do_canceltracepoint(stid, elemptr);
  2168.       ptk_unpostmenu(debugwsid, contentmenuid);
  2169.       break;
  2170.  
  2171.     case 5: /* scroll */
  2172.       ptk_unpostmenu(debugwsid, contentmenuid);
  2173.       do_scrollcontent();
  2174.       break;
  2175.   }
  2176.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);  
  2177. }  /* do_contentmenu */
  2178.  
  2179. /*--------------------------------------------------------------------------*/
  2180.  
  2181. static void do_structmenu(C(Pint) menuitem, C(Pint) windowid)
  2182. PreANSI(Pint menuitem)
  2183. PreANSI(Pint windowid)
  2184. {
  2185.   Pint_list stlist;
  2186.  
  2187.   ptk_unpostmenu(debugwsid, structmenuid);
  2188.   switch (menuitem)
  2189.   {
  2190.     case 1: /* camera */
  2191.       camerainterface(windowid);
  2192.       break;
  2193.  
  2194.     case 2: /* reset */
  2195.       ptk_resetcamera(windowid);
  2196.       stlist.num_ints = 1;
  2197.       if (windowid == structwindow)
  2198.         stlist.ints = &debugrootstid;
  2199.       else
  2200.         stlist.ints = &elemcontent;
  2201.       ptk_setcameraworld(windowid, &stlist);
  2202.       break;
  2203.   }  
  2204.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  2205. }  /* do_structmenu */
  2206.  
  2207. /*--------------------------------------------------------------------------*/
  2208.  
  2209. static void do_terminalmenu(C(Pint) menuitem)
  2210. PreANSI(Pint menuitem)
  2211. {
  2212.   ptk_unpostmenu(debugwsid, terminalmenuid);
  2213.   switch (menuitem)
  2214.   {
  2215.     case 1: /* scroll */
  2216.       do_scrollterminal();
  2217.       break;
  2218.  
  2219.     case 2: /* clear */
  2220.       ptk_clearterminal(terminalwindow);
  2221.       break;
  2222.   }  
  2223.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  2224. }  /* do_terminalmenu */
  2225.  
  2226. /*--------------------------------------------------------------------------*/
  2227.  
  2228. static void do_toptypemenu(C(Pint) menuitem)
  2229. PreANSI(Pint menuitem)
  2230. {
  2231.   switch (menuitem)
  2232.   {
  2233.     case 1: /* box */
  2234.       ptk_settopologytype(topology, PTKEBOXTOPOLOGY);
  2235.       break;
  2236.  
  2237.     case 2: /* structure */
  2238.       ptk_settopologytype(topology, PTKESTRUCTTOPOLOGY);
  2239.       break;
  2240.  
  2241.     case 3: /* structure network */
  2242.       ptk_settopologytype(topology, PTKESTRUCTNETTOPOLOGY);
  2243.       break;
  2244.   }
  2245.   ptk_unpostmenu(debugwsid, toptypemenuid);  
  2246.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  2247. }  /* do_toptypemenu */
  2248.  
  2249. /*--------------------------------------------------------------------------*/
  2250.  
  2251. static void do_tslmenu(C(Pint) menuitem)
  2252. PreANSI(Pint menuitem)
  2253. {
  2254.   Pint ind, colour, style, type, styleind, font, totsize, i;
  2255.   Pedge_flag flag;
  2256.   Ptext_prec prec;
  2257.   Ptext_path path;
  2258.   Ptext_align align;
  2259.   Ppoint charup;
  2260.   Pfloat exp, spacing, size;
  2261.   Pmatrix3 global, local;
  2262.   Pint_list nameset;
  2263.   Pint pickid, hlhsrid, viewindex;
  2264.   Paspect attrid;
  2265.   Pasf asf;
  2266.   Plimit3 bbox;
  2267.  
  2268.   switch (menuitem)
  2269.   {
  2270.     case 1: /* line */
  2271.       ptk_inqtslline(&ind, &type, &size, &colour);
  2272.       ptk_printfterminal(terminalwindow, "line index = %d\n", ind);
  2273.       ptk_printfterminal(terminalwindow, "line type = %d\n", type);
  2274.       ptk_printfterminal(terminalwindow, "linewidth = %f\n", size);
  2275.       ptk_printfterminal(terminalwindow, "line colour = %d\n", colour);
  2276.       break;
  2277.  
  2278.     case 2: /* marker */
  2279.       ptk_inqtslmarker(&ind, &type, &size, &colour);
  2280.       ptk_printfterminal(terminalwindow, "marker index = %d\n", ind);
  2281.       ptk_printfterminal(terminalwindow, "marker type = %d\n", type);
  2282.       ptk_printfterminal(terminalwindow, "marker size = %f\n", size);
  2283.       ptk_printfterminal(terminalwindow, "marker colour = %d\n", colour);
  2284.       break;
  2285.  
  2286.     case 3: /* interior */
  2287.       ptk_inqtslinterior(&ind, &style, &styleind, &colour);
  2288.       ptk_printfterminal(terminalwindow, "interior index = %d\n", ind);
  2289.       ptk_printfterminal(terminalwindow, "interior style = %d\n", style);
  2290.       ptk_printfterminal(terminalwindow, "interior style index = %d\n", styleind);
  2291.       ptk_printfterminal(terminalwindow, "interior colour = %d\n", colour);
  2292.       break;
  2293.  
  2294.     case 4: /* edge */
  2295.       ptk_inqtsledge(&ind, &flag, &type, &size, &colour);
  2296.       ptk_printfterminal(terminalwindow, "edge index = %d\n", ind);
  2297.       ptk_printfterminal(terminalwindow, "edge flag = %d\n", style);
  2298.       ptk_printfterminal(terminalwindow, "edge type = %d\n", type);
  2299.       ptk_printfterminal(terminalwindow, "edgewidth = %f\n", size);
  2300.       ptk_printfterminal(terminalwindow, "edge colour = %d\n", colour);
  2301.       break;
  2302.  
  2303.     case 5: /* text */
  2304.       ptk_inqtsltext(&ind, &font, &prec, &path, &align, &colour);
  2305.       ptk_printfterminal(terminalwindow, "text index = %d\n", ind);
  2306.       ptk_printfterminal(terminalwindow, "text font = %d\n", font);
  2307.       ptk_printfterminal(terminalwindow, "text precision = %d\n", prec);
  2308.       ptk_printfterminal(terminalwindow, "text path = %d\n", path);
  2309.       ptk_printfterminal(terminalwindow, "text alignment, hor = %d\n", align.hor);
  2310.       ptk_printfterminal(terminalwindow, "text alignment, ver = %d\n", align.vert);
  2311.       ptk_printfterminal(terminalwindow, "text colour = %d\n", colour);
  2312.       break;
  2313.  
  2314.     case 6: /* annotext */
  2315.       ptk_inqtslannotext(&style, &size, &charup, &align, &path);
  2316.       ptk_printfterminal(terminalwindow, "anno text style = %d\n", style);
  2317.       ptk_printfterminal(terminalwindow, "anno text height= %f\n", size);
  2318.       ptk_printfterminal(terminalwindow, "anno text char up = %f %f\n", 
  2319.                          charup.x, charup.y);
  2320.       ptk_printfterminal(terminalwindow, "anno text alignment, hor = %d\n", align.hor);
  2321.       ptk_printfterminal(terminalwindow, "anno text alignment, ver = %d\n", align.vert);
  2322.       ptk_printfterminal(terminalwindow, "anno text path = %d\n", path);
  2323.       break;
  2324.  
  2325.     case 7: /* char */
  2326.       ptk_inqtslchar(&exp, &spacing, &size, &charup);
  2327.       ptk_printfterminal(terminalwindow, "char expansion = %f\n", exp);
  2328.       ptk_printfterminal(terminalwindow, "char spacing = %f\n", spacing); 
  2329.       ptk_printfterminal(terminalwindow, "char height = %f\n", size);
  2330.       ptk_printfterminal(terminalwindow, "char up = %f %f\n", 
  2331.                          charup.x, charup.y);
  2332.       break;
  2333.  
  2334.     case 8: /* ctm */
  2335.       ptk_inqtslctm(global, local);
  2336.       ptk_printfterminal(terminalwindow, "global transformation:\n");
  2337.       for (i = 0; i <= 3; i++)
  2338.        ptk_printfterminal(terminalwindow, "%f %f %f %f\n", global[i][0],
  2339.                         global[i][1], global[i][2], global[i][3]);      
  2340.       ptk_printfterminal(terminalwindow, "local transformation:\n");
  2341.       for (i = 0; i <= 3; i++)
  2342.        ptk_printfterminal(terminalwindow, "%f %f %f %f\n", local[i][0],
  2343.                         local[i][1], local[i][2], local[i][3]);      
  2344.       break;
  2345.  
  2346.     case 9: /* nameset */
  2347.       ptk_inqtslnameset(0, &nameset, &totsize);
  2348.       nameset.num_ints = totsize;
  2349.       nameset.ints = (Pint *)calloc(totsize, sizeof(Pint));
  2350.       ptk_inqtslnameset(totsize, &nameset, &totsize);
  2351.       ptk_printfterminal(terminalwindow, "nameset, number = %d\n", nameset.num_ints);
  2352.       ptk_printfterminal(terminalwindow, "nameset, integers = ");
  2353.       for (i = 0; i < nameset.num_ints; i++)
  2354.         ptk_printfterminal(terminalwindow, " %d ", nameset.ints[i]);
  2355.       ptk_printfterminal(terminalwindow, "\n");
  2356.       free(nameset.ints);
  2357.       break;
  2358.  
  2359.     case 10: /* ids */
  2360.       ptk_inqtslids(&pickid, &hlhsrid, &viewindex);
  2361.       ptk_printfterminal(terminalwindow, "pick identifier = %d\n", pickid);
  2362.       ptk_printfterminal(terminalwindow, "HLHSR identifier = %d\n", hlhsrid);
  2363.       ptk_printfterminal(terminalwindow, "view index = %d\n", viewindex);
  2364.       break;
  2365.  
  2366.     case 11: /* asf */
  2367.       attrid = ptk_readint(debugwsid, 1, 
  2368.                            "Input number of attribute type>", &echoarea);
  2369.       ptk_inqtslattrasf(attrid, &asf);
  2370.       ptk_printfterminal(terminalwindow, "asf = %d\n", asf);
  2371.       break;
  2372.  
  2373.     case 12: /* bbox */
  2374.       ptk_inqboundingbox(&bbox);
  2375.       ptk_printfterminal(terminalwindow, "bounding box:\n");
  2376.       ptk_printfterminal(terminalwindow, "xmin = %f, xmax = %f\n", bbox.x_min, bbox.x_max);
  2377.       ptk_printfterminal(terminalwindow, "ymin = %f, ymax = %f\n", bbox.y_min, bbox.y_max);
  2378.       ptk_printfterminal(terminalwindow, "zmin = %f, zmax = %f\n", bbox.z_min, bbox.z_max);
  2379.       break;
  2380.   }
  2381.   ptk_unpostmenu(debugwsid, tslmenuid);  
  2382.   ptk_unpostmenu(debugwsid, tsl2menuid);  
  2383.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  2384. }  /* do_tslmenu */
  2385.  
  2386. /*--------------------------------------------------------------------------*/
  2387.  
  2388. static void do_pickinput(C(Ppick_path *) inpick)
  2389. PreANSI(Ppick_path *inpick)
  2390. {
  2391.   Pint stid, i, err;
  2392.  
  2393.   /* topology node */
  2394.   if (inpick->path_list[1].struct_id == topologystid)
  2395.   {
  2396.     ptkewindowstate state;
  2397.  
  2398.     ptk_inqwindowstate(contentwindow, &state, &err);
  2399.     if (state == PTKEWINDOWOPEN)
  2400.       pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_NIVE);
  2401.     stid = inpick->path_list[1].pick_id;
  2402.     ptk_settopologyhighlightnode(topology, stid);
  2403.     /* update structure content */
  2404.     pempty_struct(structcontent);
  2405.     ptk_openstruct(structcontent); 
  2406.     padd_names_set(&contentset);
  2407.     ptk_structcontent(debugwsid, stid, 0, PTKSTCTLIMIT, 0, 1, &err);
  2408.     currentcontent = stid;
  2409.     premove_names_set(&contentset);
  2410.     drawbreakpts(stid);
  2411.     drawtracepts(stid);
  2412.     ptk_closestruct();    
  2413.     contentlowlim = 0;
  2414.     contentuplim = PTKSTCTLIMIT;
  2415.     ptk_posttowindow(contentwindow, structcontent);
  2416.     ptk_setcontentviewrange(contentwindow, 0, 10);
  2417.     ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  2418.   }
  2419.   else   /* change structure content window */
  2420.   if (inpick->path_list[1].struct_id == structcontent)
  2421.   {
  2422.     Pint elemid, err;
  2423.     Pelem_type eltype;
  2424.  
  2425.     elemid = inpick->path_list[1].pick_id;
  2426.     ptk_openstruct(currentcontent);
  2427.     pset_elem_ptr(elemid);
  2428.     ptk_inqcurelemtype(&err, &eltype);
  2429.     if (eltype == PELEM_EXEC_STRUCT)
  2430.       do_examine(currentcontent, elemid);
  2431.     else
  2432.       do_examine(getcopystid(currentcontent), elemid);
  2433.     ptk_closestruct();
  2434.   }
  2435. }  /* do_pickinput */
  2436.  
  2437. /*--------------------------------------------------------------------------*/
  2438.  
  2439. static void debugmainloop()
  2440. {
  2441.   ptkboolean debugquit, trigger, doubletrigger;
  2442.   Pint ws, devnum;
  2443.   Pin_class class, dtclass;
  2444.   Ppoint initpt, position;
  2445.   Pint initview, view_index;
  2446.   ptksgeneralinput geninput;
  2447.   ptksmenuoutput menuoutput;
  2448.   ptkswindowoutput windowoutput;
  2449.   Ploc_data locrec;
  2450.   Plimit echo;
  2451.   Plimit3 echo3;
  2452.   Ppick_path initpath;
  2453.   Ppick_data pickdatarec;
  2454.   Pin_status status;
  2455.   Ppick_path inputpick;
  2456.   Pint err, i, stid;
  2457.   Ppick_path_elem pathel[10];
  2458.   Pint themenu;
  2459.  
  2460.   pflush_events(debugwsid, PIN_LOC, LOCDEV);
  2461.   pflush_events(debugwsid, PIN_PICK, PICKDEV);
  2462.   debugquit = FALSE;
  2463.   pset_loc_mode(debugwsid, LOCDEV, POP_REQ, PSWITCH_ECHO);
  2464.   initview = 0;
  2465.   initpt = ptk_point(0.5, 0.5);
  2466.   echo = ptk_limit(0.0, devx, 0.0, devy);
  2467.   /* Implementation dependent - locator device data record */
  2468. #ifdef HP
  2469.   locrec.pets.pet_r1.loc_colr_ind = 1;
  2470. #endif
  2471.   pinit_loc(debugwsid, LOCDEV, initview, &initpt, 1, &echo, &locrec);
  2472.   pset_loc_mode(debugwsid, LOCDEV, POP_EVENT, PSWITCH_ECHO);
  2473.   echo3 = ptk_limit3(0.0, devx, 0.0, devy, 0.0, devz);
  2474.   pset_pick_mode(debugwsid, PICKDEV, POP_REQ, PSWITCH_ECHO);
  2475.   initpath.depth = 0;
  2476.   /* Implementation dependent - pick data record */
  2477. #ifdef VMS
  2478.   pickdatarec.pets.pet_r1.aperature = 0.01;
  2479. #endif
  2480. #ifdef HP
  2481.   pickdatarec.pets.pet_r1.highl_colr_ind = 0;
  2482.   pickdatarec.pets.pet_r1.x_dim = 0.005;
  2483.   pickdatarec.pets.pet_r1.y_dim = 0.005;
  2484.   pickdatarec.pets.pet_r1.z_dim = 2.0;
  2485. #endif
  2486.   /* Implementation dependent code because of differences in
  2487.   ** valid initial status.
  2488.   */
  2489. #ifdef SUN
  2490.   pinit_pick3(debugwsid, PICKDEV, PIN_STATUS_NONE, &initpath, 1, &echo3, 
  2491.              &pickdatarec, PORDER_TOP_FIRST);
  2492. #endif
  2493. #ifdef HP
  2494.   pinit_pick3(debugwsid, PICKDEV, PIN_STATUS_NO_IN, &initpath, 1, &echo3, 
  2495.              &pickdatarec, PORDER_TOP_FIRST);
  2496. #endif
  2497. #ifdef PEXSI
  2498.   pinit_pick3(debugwsid, PICKDEV, PIN_STATUS_NO_IN, &initpath, 1, &echo3, 
  2499.              &pickdatarec, PORDER_TOP_FIRST);
  2500. #endif
  2501.   pset_pick_mode(debugwsid, PICKDEV, POP_EVENT, PSWITCH_ECHO);
  2502.   inputpick.path_list = pathel;    
  2503.   ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  2504.   do
  2505.   {
  2506.     /* update state use quick update */
  2507.     pset_disp_upd_st(debugwsid, PDEFER_WAIT, PMODE_UQUM);
  2508.     trigger = FALSE;
  2509.     doubletrigger = FALSE;
  2510.     status = PIN_STATUS_NONE;
  2511.     /* get locator and pick events */
  2512.     pawait_event(0.0, &ws, &class, &devnum);
  2513.     if ((ws == debugwsid) && ((class == PIN_LOC) || (class == PIN_PICK)))
  2514.     {
  2515.       trigger = TRUE;        
  2516.       if (class == PIN_LOC)
  2517.       {
  2518.         pget_loc(&view_index, &position);
  2519.         pawait_event(0.0, &ws, &dtclass, &devnum);
  2520.         if (dtclass == PIN_PICK)
  2521.     {
  2522.           pget_pick(10, &status, &inputpick);
  2523.           doubletrigger = TRUE;
  2524.         }
  2525.       }
  2526.       else
  2527.       {
  2528.         pget_pick(10, &status, &inputpick); 
  2529.         pawait_event(0.0, &ws, &dtclass, &devnum);
  2530.         if (dtclass == PIN_LOC)
  2531.     {
  2532.           pget_loc(&view_index, &position); 
  2533.           doubletrigger = TRUE;
  2534.         }
  2535.       }
  2536.     }
  2537.     if (trigger)
  2538.     {
  2539.       if ((!doubletrigger) && (class == PIN_PICK))
  2540.         do_pickinput(&inputpick);
  2541.       else
  2542.       {
  2543.         geninput.inputclass = PIN_LOC;
  2544.         geninput.ptkugeninput.locpoint = position;
  2545.         if (ptk_scanmenus(debugwsid, &geninput, &menuoutput))
  2546.         {
  2547.           pset_loc_mode(debugwsid, LOCDEV, POP_REQ, PSWITCH_ECHO);
  2548.           pset_pick_mode(debugwsid, PICKDEV, POP_REQ, PSWITCH_ECHO);
  2549.           if (menuoutput.menuid == debugmenuid)
  2550.           {
  2551.             if (menuoutput.itemnum == 10)
  2552.               debugquit = TRUE;
  2553.             else
  2554.               do_debugmenu(menuoutput.itemnum, &position);
  2555.           }
  2556.           else
  2557.           if (menuoutput.menuid == windowmenuid)
  2558.           {
  2559.             do_windowmenu(menuoutput.itemnum, &windowoutput);
  2560.             curmenu = 0;
  2561.           }
  2562.           else
  2563.           if (menuoutput.menuid == topologymenuid)
  2564.           {
  2565.             do_topologymenu(menuoutput.itemnum, &position);
  2566.           }
  2567.           else
  2568.           if (menuoutput.menuid == contentmenuid)
  2569.           {
  2570.             do_contentmenu(menuoutput.itemnum);
  2571.             curmenu = 0;
  2572.           }
  2573.           else
  2574.           if (menuoutput.menuid == structmenuid)
  2575.           {
  2576.             do_structmenu(menuoutput.itemnum, windowoutput.windowid);
  2577.           }
  2578.           else
  2579.           if (menuoutput.menuid == terminalmenuid)
  2580.           {
  2581.             do_terminalmenu(menuoutput.itemnum);
  2582.             curmenu = 0;
  2583.           }
  2584.           else
  2585.           if (menuoutput.menuid == toptypemenuid)
  2586.           {
  2587.             do_toptypemenu(menuoutput.itemnum);
  2588.           }
  2589.           else
  2590.           if (menuoutput.menuid == tslmenuid)
  2591.           {
  2592.             do_tslmenu(menuoutput.itemnum);
  2593.           }
  2594.           if (menuoutput.menuid == tsl2menuid)
  2595.           {
  2596.             do_tslmenu(menuoutput.itemnum + 6);
  2597.           }
  2598.           pset_loc_mode(debugwsid, LOCDEV, POP_EVENT, PSWITCH_ECHO);
  2599.           pset_pick_mode(debugwsid, PICKDEV, POP_EVENT, PSWITCH_ECHO);
  2600.           pset_pick_filter(debugwsid, PICKDEV, &pickfilt);
  2601.         }
  2602.         else
  2603.         if (ptk_scanwindows(debugwsid, &geninput, &windowoutput))
  2604.         {
  2605.           Pint err;
  2606.   
  2607.           if (doubletrigger && (status == PIN_STATUS_OK) && 
  2608.                  ((windowoutput.windowid == topologywindow) || 
  2609.                   (windowoutput.windowid == contentwindow)))
  2610.             do_pickinput(&inputpick);
  2611.           else
  2612.           if ((windowoutput.windowarea == PTKEWINDOWICON) ||
  2613.               (windowoutput.windowarea == PTKEWINDOWBANNER))
  2614.           {
  2615.             ptk_unpostallmenu(debugwsid);
  2616.             if (windowoutput.windowarea == PTKEWINDOWICON)
  2617.               ptk_createtextmenuitem(windowmenuid, "open", 1, PEDIT_REPLACE, 
  2618.                                      &err);
  2619.             else
  2620.               ptk_createtextmenuitem(windowmenuid, "close", 1, PEDIT_REPLACE, 
  2621.                                      &err);
  2622.             ptk_setmenuposition(windowmenuid, &position);
  2623.             if ((curmenu != windowmenuid) ||
  2624.                 (curwindow != windowoutput.windowid))
  2625.           {
  2626.               ptk_postmenu(debugwsid, windowmenuid);
  2627.               curmenu = windowmenuid;
  2628.               curwindow = windowoutput.windowid;
  2629.             }
  2630.             else
  2631.           {
  2632.               curmenu = 0;
  2633.               curwindow = 0;
  2634.             }
  2635.             ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  2636.           }
  2637.           else
  2638.         {
  2639.             if (windowoutput.windowid == topologywindow)
  2640.               themenu = topologymenuid;
  2641.             else
  2642.             if (windowoutput.windowid == contentwindow)
  2643.               themenu = contentmenuid;
  2644.             else
  2645.             if ((windowoutput.windowid == structwindow) ||
  2646.                 (windowoutput.windowid == elementwindow))
  2647.               themenu = structmenuid;
  2648.             else
  2649.             if (windowoutput.windowid == terminalwindow)
  2650.               themenu = terminalmenuid;
  2651.             ptk_unpostallmenu(debugwsid);
  2652.             if ((curmenu != themenu) || 
  2653.                 (curwindow != windowoutput.windowid))
  2654.           {
  2655.               ptk_setmenuposition(themenu, &position);
  2656.               ptk_postmenu(debugwsid, themenu);
  2657.               curmenu = themenu;
  2658.               curwindow = windowoutput.windowid;
  2659.             }
  2660.             else
  2661.           {
  2662.               curmenu = 0;
  2663.               curwindow = 0;
  2664.             }
  2665.             ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);          
  2666.           }
  2667.         }
  2668.         else
  2669.         {        
  2670.           curwindow = 0;
  2671.           ptk_unpostallmenu(debugwsid);
  2672.           if (curmenu != debugmenuid)
  2673.         {
  2674.             ptk_setmenuposition(debugmenuid, &position);
  2675.             ptk_postmenu(debugwsid, debugmenuid);
  2676.             curmenu = debugmenuid;
  2677.           }
  2678.           else
  2679.             curmenu = 0;
  2680.           ptk_redrawallstructs(debugwsid, PFLAG_ALWAYS);
  2681.         }
  2682.       }
  2683.     }
  2684.     /* Implementation dependent - for some reason PEX-SI requires
  2685.     ** the pick device mode to be re-set after each trigger/event.
  2686.     */
  2687. #ifdef PEXSI
  2688.     pset_pick_mode(debugwsid, PICKDEV, POP_EVENT, PSWITCH_ECHO);
  2689. #endif
  2690.   } while (!debugquit);
  2691.   pflush_events(debugwsid, PIN_LOC, LOCDEV);
  2692.   pflush_events(debugwsid, PIN_PICK, PICKDEV);
  2693. }  /* debugmainloop */
  2694.  
  2695. /*--------------------------------------------------------------------------*/
  2696.  
  2697. /*function:external*/
  2698. extern void ptk_debugger(C(Pint) wsid, C(Pint) stid)
  2699. PreANSI(Pint wsid)
  2700. PreANSI(Pint stid)
  2701. /*
  2702. ** \parambegin
  2703. ** \param{Pint}{wsid}{workstation identifier}{IN}
  2704. ** \param{Pint}{stid}{structure identifier}{IN}
  2705. ** \paramend
  2706. ** \blurb{This function starts the PHIGS debugger on workstation
  2707. ** \pardesc{wsid}, and makes structure \pardesc{stid} the root of the 
  2708. ** structure network to be debugged. This function requires hashtables
  2709. ** "structureid", "label", "name", "viewindex", "topologyid", "menuid",
  2710. ** "windowid".}
  2711. */
  2712. {
  2713.   Ppoint pos, size;
  2714.   char ststr[20], str[20];
  2715.   Pint lenstr, err, stcom, i, totsize;
  2716.   Pint_list pmenus, pwindows;
  2717.   Pposted_struct_list structs;
  2718.   Pdefer_mode defmode;
  2719.   Pmod_mode modmode;
  2720.   Pdisp_surf_empty dspsurf;
  2721.   Pvisual_st visualrep;
  2722.   Pcolr_rep backrep;
  2723.   ptksexeclist *ptr, *temp;
  2724.  
  2725.   if (!ptk_structexists(stid))
  2726.   {
  2727.     fprintf(stderr, "Debugger: the given structure does not exist.\n");
  2728.     return;
  2729.   }
  2730.  
  2731.   /* inquire and set display update state */
  2732.   pinq_disp_upd_st(wsid, &err, &defmode, &modmode, &dspsurf, &visualrep);
  2733.   pset_disp_upd_st(wsid, PDEFER_WAIT, PMODE_NIVE); 
  2734.  
  2735.   /* inquire and set background colour */
  2736.   pinq_colr_rep(wsid, 0, PINQ_SET, &err, &backrep);
  2737.   ptk_setbackgroundcolourind(wsid, backgroundcolourind);
  2738.  
  2739.   /* inquire all posted menus and windows */
  2740.   ptk_inqpostedmenus(wsid, 0, &pmenus, &totsize, &err);
  2741.   pmenus.ints = (Pint *)calloc(totsize, sizeof(Pint));
  2742.   ptk_inqpostedmenus(wsid, totsize, &pmenus, &totsize, &err);
  2743.   pmenus.num_ints = totsize;
  2744.   ptk_inqpostedwindows(wsid, 0, &pwindows, &totsize, &err);
  2745.   pwindows.ints = (Pint *)calloc(totsize, sizeof(Pint));
  2746.   ptk_inqpostedwindows(wsid, totsize, &pwindows, &totsize, &err);
  2747.   pwindows.num_ints = totsize;
  2748.   /* clear menus and windows */
  2749.   for (i = 0; i < pmenus.num_ints; i++)
  2750.     ptk_unpostmenu(wsid, pmenus.ints[i]);
  2751.   for (i = 0; i < pwindows.num_ints; i++)
  2752.     ptk_unpostwindow(wsid, pwindows.ints[i]);
  2753.  
  2754.   /* inquire all other posted structure */
  2755.   pinq_posted_structs(wsid, 0, 0, &err, &structs, &totsize);
  2756.   structs.postings = (Pposted_struct *)calloc(totsize, sizeof(Pposted_struct));
  2757.   pinq_posted_structs(wsid, totsize, 0, &err, &structs, &totsize);
  2758.   structs.num_postings = totsize;
  2759.   /* clear all posted structures */
  2760.   punpost_all_structs(wsid);
  2761.  
  2762.   /* stack TSL */
  2763.   ptk_stacktsl();
  2764.  
  2765.   /* clear workstation */
  2766.  
  2767.   debugwsid = wsid;
  2768.   debugrootstid = stid;
  2769.   /* set up windows */
  2770.   pos = ptk_point(0.25, 0.25);
  2771.   size = ptk_point(0.45, 0.45);     
  2772.  
  2773.   structwindow = ptk_stringtoint("windowid", "ptk$dbgstructwindow");
  2774.   topologywindow = ptk_stringtoint("windowid", "ptk$dbgtopologywindow");
  2775.   contentwindow = ptk_stringtoint("windowid", "ptk$dbgcontentwindow");
  2776.   terminalwindow = ptk_stringtoint("windowid", "ptk$dbgterminalwindow");
  2777.   elementwindow = ptk_stringtoint("windowid", "ptk$dbgelementwindow");
  2778.   ptk_createwindow(wsid, structwindow, &size, &pos, "structure");
  2779.   ptk_setwindowattrs(structwindow, windowtextfont, bannertextcolourind,
  2780.                      bannercolourind,  windowcolourind, bannercolourind, 
  2781.                      tlcolourind, brcolourind);
  2782.   pos = ptk_point(0.25, 0.75);
  2783.   ptk_createwindow(wsid, topologywindow, &size, &pos, "topology");
  2784.   ptk_setwindowattrs(topologywindow, windowtextfont, bannertextcolourind,
  2785.                      bannercolourind,  windowcolourind, bannercolourind, 
  2786.                      tlcolourind, brcolourind);
  2787.   pos = ptk_point(0.75, 0.75);
  2788.   ptk_createwindow(wsid, contentwindow, &size, &pos, "content");
  2789.   ptk_setwindowattrs(contentwindow, windowtextfont, bannertextcolourind,
  2790.                      bannercolourind,  windowcolourind, bannercolourind, 
  2791.                      tlcolourind, brcolourind);
  2792.   pos = ptk_point(0.75, 0.25);
  2793.   ptk_createwindow(wsid, terminalwindow, &size, &pos, "terminal");
  2794.   ptk_setwindowattrs(terminalwindow, windowtextfont, bannertextcolourind,
  2795.                      bannercolourind,  windowcolourind, bannercolourind, 
  2796.                      tlcolourind, brcolourind);
  2797.   pos = ptk_point(0.5, 0.5);
  2798.   ptk_createwindow(wsid, elementwindow, &size, &pos, "element");
  2799.   ptk_setwindowattrs(elementwindow, windowtextfont, bannertextcolourind,
  2800.                      bannercolourind,  windowcolourind, bannercolourind, 
  2801.                      tlcolourind, brcolourind);
  2802.   ptk_setwindowtype(topologywindow, PTKETOPOLOGYWINDOW);
  2803.   ptk_setwindowtype(contentwindow, PTKECONTENTWINDOW); 
  2804.   ptk_setwindowtype(terminalwindow, PTKETERMINALWINDOW); 
  2805.   ptk_postwindow(structwindow);
  2806.   ptk_postwindow(terminalwindow); 
  2807.   ptk_postwindow(topologywindow);
  2808.   ptk_postwindow(contentwindow);
  2809.  
  2810.   /* set up menus */
  2811.   makemenus();
  2812.  
  2813.   ptk_inqmaxdevicecoords3(debugwsid, &devx, &devy, &devz);
  2814.   echoarea = ptk_limit(0.0, devx * 0.5, 0.0, devy * 0.05);
  2815.   setupdebugger();
  2816.  
  2817.   /* make a copy of the structure network so that 
  2818.   ** deposit doesn't affect the original.
  2819.   */
  2820.   copynetwork(stid);  
  2821.  
  2822.   /* set up debugger traversal */
  2823.   initialisedebugger(stid);
  2824.  
  2825.   ptk_settslstart(getcopystid(stid), 0);
  2826.   ptk_tsltraversenext();
  2827.  
  2828.   /* interaction loop */
  2829.   debugmainloop();
  2830.  
  2831.   pset_disp_upd_st(wsid, PDEFER_WAIT, PMODE_NIVE); 
  2832.  
  2833.   /* tidy up before exit */
  2834.   ptk_delwindow(structwindow);
  2835.   ptk_delwindow(topologywindow);
  2836.   ptk_delwindow(contentwindow);
  2837.   ptk_delwindow(terminalwindow);
  2838.   ptk_delwindow(elementwindow);
  2839.  
  2840.   /* reset debugger variables */
  2841.   elemposted = FALSE;
  2842.   debugstack = NULL;
  2843.   stpoints = NULL;
  2844.   dbgcount = 0;
  2845.   debugstackdepth = 0;
  2846.   curmenu = 0;
  2847.   curwindow = 0;
  2848.   topview = ptk_limit(0.0, 1.0, 0.0, 1.0);
  2849.  
  2850.   ptk_delstring("windowid", "ptk$dbgstructwindow");
  2851.   ptk_delstring("windowid", "ptk$dbgtopologywindow");
  2852.   ptk_delstring("windowid", "ptk$dbgcontentwindow");
  2853.   ptk_delstring("windowid", "ptk$dbgterminalwindow");
  2854.   ptk_delstring("windowid", "ptk$dbgelementwindow");
  2855.  
  2856.   ptk_delmenu(debugmenuid);
  2857.   ptk_delmenu(windowmenuid);
  2858.   ptk_delmenu(topologymenuid);
  2859.   ptk_delmenu(contentmenuid);
  2860.   ptk_delmenu(structmenuid); 
  2861.   ptk_delmenu(terminalmenuid);
  2862.   ptk_delmenu(toptypemenuid);
  2863.   ptk_delmenu(tslmenuid);
  2864.   ptk_delmenu(tsl2menuid);
  2865.  
  2866.   ptk_delstring("menuid", "ptk$debugmenu");
  2867.   ptk_delstring("menuid", "ptk$windowmenu");
  2868.   ptk_delstring("menuid", "ptk$topologymenu");
  2869.   ptk_delstring("menuid", "ptk$contentmenu");
  2870.   ptk_delstring("menuid", "ptk$structmenu"); 
  2871.   ptk_delstring("menuid", "ptk$terminalmenu");
  2872.   ptk_delstring("menuid", "ptk$toptypemenu");
  2873.   ptk_delstring("menuid", "ptk$tslmenu");
  2874.   ptk_delstring("menuid", "ptk$tsl2menu");
  2875.  
  2876.   ptk_delmenu(rot3d1);
  2877.   ptk_delmenu(rot3d2);
  2878.   ptk_delmenu(rot2d1);
  2879.   ptk_delmenu(rot2d2);
  2880.   ptk_delmenu(rot1d);
  2881.  
  2882.   ptk_delstring("menuid", "ptk$rotator3d1");
  2883.   ptk_delstring("menuid", "ptk$rotator3d2");
  2884.   ptk_delstring("menuid", "ptk$rotator2d1");
  2885.   ptk_delstring("menuid", "ptk$rotator2d2");
  2886.   ptk_delstring("menuid", "ptk$rotator1d");
  2887.  
  2888.   ptk_deltopology(topology);
  2889.  
  2890.   deletecopynetwork();
  2891.   clearstructid();
  2892.   pdel_struct(elemcontent);
  2893.   pdel_struct(elembuffer);
  2894.   pdel_struct(structcontent);
  2895.  
  2896.   /* unstack TSL */
  2897.   ptk_tsltraversetoend();
  2898.   ptk_unstacktsl();
  2899.  
  2900.   /* free break/trace points */
  2901.   ptr = stpoints;
  2902.   while (ptr != NULL)
  2903.   {
  2904.     temp = ptr->next;
  2905.     free(ptr->bkpts);
  2906.     free(ptr->tcpts);
  2907.     free(ptr);
  2908.     ptr = temp;
  2909.   }  
  2910.  
  2911.   /* repost all menus, windows and other structs */
  2912.   for (i = 0; i < structs.num_postings; i++)
  2913.     ppost_struct(wsid, structs.postings[i].id, structs.postings[i].disp_pri);
  2914.   for (i = 0; i < pwindows.num_ints; i++)
  2915.     ptk_postwindow(pwindows.ints[i]);
  2916.   for (i = 0; i < pmenus.num_ints; i++)
  2917.     ptk_postmenu(wsid, pmenus.ints[i]);
  2918.   free(structs.postings);
  2919.   free(pmenus.ints);
  2920.   free(pwindows.ints);
  2921.  
  2922.   /* background colour */
  2923.   pset_colr_rep(wsid, 0, &backrep);
  2924.  
  2925.   ptk_redrawallstructs(wsid, PFLAG_ALWAYS);
  2926.  
  2927.   /* restore display update state */
  2928.   pset_disp_upd_st(wsid, defmode, modmode); 
  2929. }  /* ptk_debugger */
  2930.  
  2931. /*--------------------------------------------------------------------------*/
  2932.  
  2933. /*function:external*/
  2934. extern void ptk_setdebuggerattrs(C(Pint) menufont, 
  2935.               C(Pint) windowfont, C(Pint) menucol, C(Pint) menutextcol, 
  2936.               C(Pint) windowcol, C(Pint) bannercol, C(Pint) bannertextcol, 
  2937.        C(Pint) tlcol, C(Pint) brcol, C(Pint) arrowcol, C(Pint) arrowedgecol)
  2938. PreANSI(Pint menufont)
  2939. PreANSI(Pint windowfont)
  2940. PreANSI(Pint menucol)
  2941. PreANSI(Pint menutextcol)
  2942. PreANSI(Pint windowcol)
  2943. PreANSI(Pint bannercol)
  2944. PreANSI(Pint bannertextcol)
  2945. PreANSI(Pint tlcol)
  2946. PreANSI(Pint brcol)
  2947. PreANSI(Pint arrowcol)
  2948. PreANSI(Pint arrowedgecol)
  2949. /*
  2950. ** \parambegin
  2951. ** \param{Pint}{menufont}{menu text font}{IN}
  2952. ** \param{Pint}{windowfont}{window text font}{IN}
  2953. ** \param{Pint}{menucol}{menu colour index}{IN}
  2954. ** \param{Pint}{menutextcol}{menu text colour index}{IN}
  2955. ** \param{Pint}{windowcol}{window interior colour index}{IN}
  2956. ** \param{Pint}{bannercol}{window banner colour index}{IN}
  2957. ** \param{Pint}{bannertextcol}{window banner text colour index}{IN}
  2958. ** \param{Pint}{tlcol}{top-left colour index}{IN}
  2959. ** \param{Pint}{brcol}{bottom-right colour index}{IN}
  2960. ** \param{Pint}{arrowcol}{arrow colour index}{IN}
  2961. ** \param{Pint}{arrowedgecol}{arrow edge colour index}{IN}
  2962. ** \paramend
  2963. ** \blurb{This function enables an application to set
  2964. **  the fonts and colours of menus and windows in the PHIGS debugger.}
  2965. */
  2966. {
  2967.   menutextfont = menufont;
  2968.   windowtextfont = windowfont;
  2969.   menucolourind = menucol;
  2970.   windowcolourind = windowcol;
  2971.   menutextcolourind = menutextcol;
  2972.   bannercolourind = bannercol;
  2973.   bannertextcolourind = bannertextcol;
  2974.   tlcolourind = tlcol;
  2975.   brcolourind = brcol;
  2976.   arrowcolourind = arrowcol;
  2977.   arrowedgecolourind = arrowedgecol;
  2978. } /* ptk_setdebuggerattrs */
  2979.  
  2980. /*--------------------------------------------------------------------------*/
  2981.  
  2982. /*function:external*/
  2983. extern void ptk_inqdebuggerattrs(C(Pint *) menufont, C(Pint *) windowfont, 
  2984.            C(Pint *) menucol, C(Pint *) menutextcol, C(Pint *) windowcol, 
  2985.            C(Pint *) bannercol, C(Pint *) bannertextcol, C(Pint *) tlcol, 
  2986.            C(Pint *) brcol, C(Pint *) arrowcol, C(Pint *) arrowedgecol)
  2987. PreANSI(Pint *menufont)
  2988. PreANSI(Pint *windowfont)
  2989. PreANSI(Pint *menucol)
  2990. PreANSI(Pint *menutextcol)
  2991. PreANSI(Pint *windowcol)
  2992. PreANSI(Pint *bannercol)
  2993. PreANSI(Pint *bannertextcol)
  2994. PreANSI(Pint *tlcol)
  2995. PreANSI(Pint *brcol)
  2996. PreANSI(Pint *arrowcol)
  2997. PreANSI(Pint *arrowedgecol)
  2998. /*
  2999. ** \parambegin
  3000. ** \param{Pint *}{menufont}{menu text font}{IN}
  3001. ** \param{Pint *}{windowfont}{window text font}{IN}
  3002. ** \param{Pint *}{menucol}{menu colour index}{IN}
  3003. ** \param{Pint *}{menutextcol}{menu text colour index}{IN}
  3004. ** \param{Pint *}{windowcol}{window interior colour index}{IN}
  3005. ** \param{Pint *}{bannercol}{window banner colour index}{IN}
  3006. ** \param{Pint *}{bannertextcol}{window banner text colour index}{IN}
  3007. ** \param{Pint *}{tlcol}{top-left colour index}{IN}
  3008. ** \param{Pint *}{brcol}{bottom-right colour index}{IN}
  3009. ** \param{Pint *}{arrowcol}{arrow colour index}{IN}
  3010. ** \param{Pint *}{arrowedgecol}{arrow edge colour index}{IN}
  3011. ** \paramend
  3012. ** \blurb{This function may be used to obtain the text font and 
  3013. ** colour attribute values of menus and windows used in the PHIGS debugger.}
  3014. */
  3015. {
  3016.   *menufont = menutextfont;
  3017.   *windowfont = windowtextfont;
  3018.   *menucol = menucolourind;
  3019.   *windowcol = windowcolourind;
  3020.   *menutextcol = menutextcolourind;
  3021.   *bannercol = bannercolourind;
  3022.   *bannertextcol = bannertextcolourind;
  3023.   *tlcol = tlcolourind;
  3024.   *brcol = brcolourind;
  3025.   *arrowcol = arrowcolourind;
  3026.   *arrowedgecol = arrowedgecolourind;
  3027. } /* ptk_inqdebuggerattrs */
  3028.  
  3029. /*--------------------------------------------------------------------------*/
  3030.  
  3031. /* end of dbug.c */
  3032.